From bf92802e0252315e9753a2817d22fd885b40111f Mon Sep 17 00:00:00 2001 From: Felix Morgner Date: Wed, 30 Sep 2026 17:55:16 +0200 Subject: kstd: ring_buffer: simplify element_at --- libs/kstd/kstd/ring_buffer.hpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'libs/kstd') diff --git a/libs/kstd/kstd/ring_buffer.hpp b/libs/kstd/kstd/ring_buffer.hpp index 075701ee..d8873b2c 100644 --- a/libs/kstd/kstd/ring_buffer.hpp +++ b/libs/kstd/kstd/ring_buffer.hpp @@ -137,9 +137,8 @@ namespace kstd //! @return A pointer to the object at given position. constexpr auto element_at(size_type position) noexcept -> pointer { - auto base_pointer = reinterpret_cast(m_storage.data()); auto storage_index = (m_read_index + position) % capacity(); - return base_pointer + storage_index; + return &m_storage[storage_index].value; } //! Get a pointer to the element at the given read-index relative position. @@ -148,7 +147,8 @@ namespace kstd //! @return A pointer to the object at given position. constexpr auto element_at(size_type position) const noexcept -> const_pointer { - return const_cast(this)->element_at_index(position); + auto storage_index = (m_read_index + position) % capacity(); + return &m_storage[storage_index].value; } //! Trigger a kernel panic if an attempt is made to use an invalid index. -- cgit v1.2.3