diff options
author | Chris Robinson <[email protected]> | 2024-01-03 19:10:15 -0800 |
---|---|---|
committer | Chris Robinson <[email protected]> | 2024-01-03 19:10:15 -0800 |
commit | 8c80f29e242dee18cb914d3cdb396bd96e935547 (patch) | |
tree | 1ec189802b81060295edcffa5b77976a6373b9d5 /common | |
parent | 18349e1da2c79d0f41c8c4f12ccd065f91618a6f (diff) |
Avoid some const_casts
Diffstat (limited to 'common')
-rw-r--r-- | common/althrd_setname.cpp | 2 | ||||
-rw-r--r-- | common/ringbuffer.cpp | 16 | ||||
-rw-r--r-- | common/ringbuffer.h | 5 |
3 files changed, 11 insertions, 12 deletions
diff --git a/common/althrd_setname.cpp b/common/althrd_setname.cpp index 22d33092..21197ba0 100644 --- a/common/althrd_setname.cpp +++ b/common/althrd_setname.cpp @@ -60,7 +60,7 @@ using setname_t4 = int(*)(pthread_t, const char*, void*); { func(pthread_self(), name); } [[maybe_unused]] void setname_caller(setname_t4 func, const char *name) -{ func(pthread_self(), "%s", static_cast<void*>(const_cast<char*>(name))); } +{ func(pthread_self(), "%s", const_cast<char*>(name)); /* NOLINT(*-const-cast) */ } } // namespace diff --git a/common/ringbuffer.cpp b/common/ringbuffer.cpp index 96a2b615..2636bfb4 100644 --- a/common/ringbuffer.cpp +++ b/common/ringbuffer.cpp @@ -161,7 +161,7 @@ std::size_t RingBuffer::write(const void *src, std::size_t cnt) noexcept } -auto RingBuffer::getReadVector() const noexcept -> DataPair +auto RingBuffer::getReadVector() noexcept -> DataPair { DataPair ret; @@ -176,15 +176,15 @@ auto RingBuffer::getReadVector() const noexcept -> DataPair { /* Two part vector: the rest of the buffer after the current read ptr, * plus some from the start of the buffer. */ - ret.first.buf = const_cast<std::byte*>(mBuffer.data() + r*mElemSize); + ret.first.buf = mBuffer.data() + r*mElemSize; ret.first.len = mSizeMask+1 - r; - ret.second.buf = const_cast<std::byte*>(mBuffer.data()); + ret.second.buf = mBuffer.data(); ret.second.len = cnt2 & mSizeMask; } else { /* Single part vector: just the rest of the buffer */ - ret.first.buf = const_cast<std::byte*>(mBuffer.data() + r*mElemSize); + ret.first.buf = mBuffer.data() + r*mElemSize; ret.first.len = free_cnt; ret.second.buf = nullptr; ret.second.len = 0; @@ -193,7 +193,7 @@ auto RingBuffer::getReadVector() const noexcept -> DataPair return ret; } -auto RingBuffer::getWriteVector() const noexcept -> DataPair +auto RingBuffer::getWriteVector() noexcept -> DataPair { DataPair ret; @@ -208,14 +208,14 @@ auto RingBuffer::getWriteVector() const noexcept -> DataPair { /* Two part vector: the rest of the buffer after the current write ptr, * plus some from the start of the buffer. */ - ret.first.buf = const_cast<std::byte*>(mBuffer.data() + w*mElemSize); + ret.first.buf = mBuffer.data() + w*mElemSize; ret.first.len = mSizeMask+1 - w; - ret.second.buf = const_cast<std::byte*>(mBuffer.data()); + ret.second.buf = mBuffer.data(); ret.second.len = cnt2 & mSizeMask; } else { - ret.first.buf = const_cast<std::byte*>(mBuffer.data() + w*mElemSize); + ret.first.buf = mBuffer.data() + w*mElemSize; ret.first.len = free_cnt; ret.second.buf = nullptr; ret.second.len = 0; diff --git a/common/ringbuffer.h b/common/ringbuffer.h index a2b820eb..ee59205a 100644 --- a/common/ringbuffer.h +++ b/common/ringbuffer.h @@ -33,7 +33,6 @@ public: }; using DataPair = std::pair<Data,Data>; - RingBuffer(const std::size_t count) : mBuffer{count} { } /** Reset the read and write pointers to zero. This is not thread safe. */ @@ -44,13 +43,13 @@ public: * hold the current readable data. If the readable data is in one segment * the second segment has zero length. */ - [[nodiscard]] auto getReadVector() const noexcept -> DataPair; + [[nodiscard]] auto getReadVector() noexcept -> DataPair; /** * The non-copying data writer. Returns two ringbuffer data pointers that * hold the current writeable data. If the writeable data is in one segment * the second segment has zero length. */ - [[nodiscard]] auto getWriteVector() const noexcept -> DataPair; + [[nodiscard]] auto getWriteVector() noexcept -> DataPair; /** * Return the number of elements available for reading. This is the number |