diff options
| author | Felix Morgner <felix.morgner@ost.ch> | 2026-09-30 17:55:16 +0200 |
|---|---|---|
| committer | Felix Morgner <felix.morgner@ost.ch> | 2026-09-30 18:00:04 +0200 |
| commit | bf92802e0252315e9753a2817d22fd885b40111f (patch) | |
| tree | 2fcae1c7127aa03035160d76b7910cd51f9803ae /libs | |
| parent | 685a9b6403180957e2ef4e200088ecca0de40017 (diff) | |
| download | kernel-bf92802e0252315e9753a2817d22fd885b40111f.tar.xz kernel-bf92802e0252315e9753a2817d22fd885b40111f.zip | |
kstd: ring_buffer: simplify element_at
Diffstat (limited to 'libs')
| -rw-r--r-- | libs/kstd/kstd/ring_buffer.hpp | 6 |
1 files changed, 3 insertions, 3 deletions
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<pointer>(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<ring_buffer *>(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. |
