aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorChris Robinson <[email protected]>2024-01-03 19:10:15 -0800
committerChris Robinson <[email protected]>2024-01-03 19:10:15 -0800
commit8c80f29e242dee18cb914d3cdb396bd96e935547 (patch)
tree1ec189802b81060295edcffa5b77976a6373b9d5
parent18349e1da2c79d0f41c8c4f12ccd065f91618a6f (diff)
Avoid some const_casts
-rw-r--r--alc/alu.cpp9
-rw-r--r--alc/backends/jack.cpp4
-rw-r--r--common/althrd_setname.cpp2
-rw-r--r--common/ringbuffer.cpp16
-rw-r--r--common/ringbuffer.h5
-rw-r--r--core/ambdec.cpp2
-rw-r--r--core/except.cpp2
7 files changed, 19 insertions, 21 deletions
diff --git a/alc/alu.cpp b/alc/alu.cpp
index 59b5a551..b50eaa41 100644
--- a/alc/alu.cpp
+++ b/alc/alu.cpp
@@ -1912,7 +1912,7 @@ void ProcessVoiceChanges(ContextBase *ctx)
ctx->mCurrentVoiceChange.store(cur, std::memory_order_release);
}
-void ProcessParamUpdates(ContextBase *ctx, const EffectSlotArray &slots,
+void ProcessParamUpdates(ContextBase *ctx, const al::span<EffectSlot*> slots,
const al::span<Voice*> voices)
{
ProcessVoiceChanges(ctx);
@@ -1921,7 +1921,7 @@ void ProcessParamUpdates(ContextBase *ctx, const EffectSlotArray &slots,
if(!ctx->mHoldUpdates.load(std::memory_order_acquire)) LIKELY
{
bool force{CalcContextParams(ctx)};
- auto sorted_slots = const_cast<EffectSlot**>(slots.data() + slots.size());
+ auto sorted_slots = al::to_address(slots.end());
for(EffectSlot *slot : slots)
force |= CalcEffectSlotParams(slot, sorted_slots, ctx);
@@ -1945,7 +1945,7 @@ void ProcessContexts(DeviceBase *device, const uint SamplesToDo)
for(ContextBase *ctx : *device->mContexts.load(std::memory_order_acquire))
{
- const EffectSlotArray &auxslots = *ctx->mActiveAuxSlots.load(std::memory_order_acquire);
+ auto auxslots = al::span{*ctx->mActiveAuxSlots.load(std::memory_order_acquire)};
const al::span<Voice*> voices{ctx->getVoicesSpanAcquired()};
/* Process pending property updates for objects on the context. */
@@ -1972,8 +1972,7 @@ void ProcessContexts(DeviceBase *device, const uint SamplesToDo)
/* Sort the slots into extra storage, so that effect slots come
* before their effect slot target (or their targets' target).
*/
- const al::span sorted_slots{const_cast<EffectSlot**>(al::to_address(auxslots.end())),
- auxslots.size()};
+ const al::span sorted_slots{al::to_address(auxslots.end()), auxslots.size()};
/* Skip sorting if it has already been done. */
if(!sorted_slots[0])
{
diff --git a/alc/backends/jack.cpp b/alc/backends/jack.cpp
index 1e5c17ad..529bb9fe 100644
--- a/alc/backends/jack.cpp
+++ b/alc/backends/jack.cpp
@@ -371,7 +371,7 @@ int JackPlayback::process(jack_nframes_t numframes) noexcept
jack_nframes_t todo{minu(numframes, static_cast<uint>(data.first.len))};
auto write_first = [&data,numchans,todo](float *outbuf) -> float*
{
- const float *RESTRICT in = reinterpret_cast<float*>(data.first.buf);
+ const auto *RESTRICT in = reinterpret_cast<const float*>(data.first.buf);
auto deinterlace_input = [&in,numchans]() noexcept -> float
{
float ret{*in};
@@ -390,7 +390,7 @@ int JackPlayback::process(jack_nframes_t numframes) noexcept
{
auto write_second = [&data,numchans,todo](float *outbuf) -> float*
{
- const float *RESTRICT in = reinterpret_cast<float*>(data.second.buf);
+ const auto *RESTRICT in = reinterpret_cast<const float*>(data.second.buf);
auto deinterlace_input = [&in,numchans]() noexcept -> float
{
float ret{*in};
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
diff --git a/core/ambdec.cpp b/core/ambdec.cpp
index 8242cf02..f3fe7566 100644
--- a/core/ambdec.cpp
+++ b/core/ambdec.cpp
@@ -53,7 +53,7 @@ std::optional<std::string> make_error(size_t linenum, const char *fmt, ...)
auto &str = ret.emplace();
str.resize(256);
- int printed{std::snprintf(const_cast<char*>(str.data()), str.length(), "Line %zu: ", linenum)};
+ int printed{std::snprintf(str.data(), str.length(), "Line %zu: ", linenum)};
if(printed < 0) printed = 0;
auto plen = std::min(static_cast<size_t>(printed), str.length());
diff --git a/core/except.cpp b/core/except.cpp
index 45fd4eb5..86c7ccca 100644
--- a/core/except.cpp
+++ b/core/except.cpp
@@ -21,7 +21,7 @@ void base_exception::setMessage(const char* msg, std::va_list args)
if(msglen > 0) LIKELY
{
mMessage.resize(static_cast<size_t>(msglen)+1);
- std::vsnprintf(const_cast<char*>(mMessage.data()), mMessage.length(), msg, args2);
+ std::vsnprintf(mMessage.data(), mMessage.length(), msg, args2);
mMessage.pop_back();
}
va_end(args2);