aboutsummaryrefslogtreecommitdiff
path: root/libs
diff options
context:
space:
mode:
authorFelix Morgner <felix.morgner@ost.ch>2026-09-30 17:55:16 +0200
committerFelix Morgner <felix.morgner@ost.ch>2026-09-30 18:00:04 +0200
commitbf92802e0252315e9753a2817d22fd885b40111f (patch)
tree2fcae1c7127aa03035160d76b7910cd51f9803ae /libs
parent685a9b6403180957e2ef4e200088ecca0de40017 (diff)
downloadkernel-bf92802e0252315e9753a2817d22fd885b40111f.tar.xz
kernel-bf92802e0252315e9753a2817d22fd885b40111f.zip
kstd: ring_buffer: simplify element_at
Diffstat (limited to 'libs')
-rw-r--r--libs/kstd/kstd/ring_buffer.hpp6
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.