util/PeakBuffer: use std::size_t

This commit is contained in:
Max Kellermann 2021-01-21 16:37:14 +01:00
parent dafba203e7
commit 6b555b7017
2 changed files with 11 additions and 11 deletions

View File

@ -57,7 +57,7 @@ PeakBuffer::Read() const noexcept
} }
void void
PeakBuffer::Consume(size_t length) noexcept PeakBuffer::Consume(std::size_t length) noexcept
{ {
if (normal_buffer != nullptr && !normal_buffer->empty()) { if (normal_buffer != nullptr && !normal_buffer->empty()) {
normal_buffer->Consume(length); normal_buffer->Consume(length);
@ -75,21 +75,21 @@ PeakBuffer::Consume(size_t length) noexcept
} }
} }
static size_t static std::size_t
AppendTo(DynamicFifoBuffer<uint8_t> &buffer, AppendTo(DynamicFifoBuffer<uint8_t> &buffer,
const void *data, size_t length) noexcept const void *data, size_t length) noexcept
{ {
assert(data != nullptr); assert(data != nullptr);
assert(length > 0); assert(length > 0);
size_t total = 0; std::size_t total = 0;
do { do {
const auto p = buffer.Write(); const auto p = buffer.Write();
if (p.empty()) if (p.empty())
break; break;
const size_t nbytes = std::min(length, p.size); const std::size_t nbytes = std::min(length, p.size);
memcpy(p.data, data, nbytes); memcpy(p.data, data, nbytes);
buffer.Append(nbytes); buffer.Append(nbytes);
@ -102,20 +102,20 @@ AppendTo(DynamicFifoBuffer<uint8_t> &buffer,
} }
bool bool
PeakBuffer::Append(const void *data, size_t length) PeakBuffer::Append(const void *data, std::size_t length)
{ {
if (length == 0) if (length == 0)
return true; return true;
if (peak_buffer != nullptr && !peak_buffer->empty()) { if (peak_buffer != nullptr && !peak_buffer->empty()) {
size_t nbytes = AppendTo(*peak_buffer, data, length); std::size_t nbytes = AppendTo(*peak_buffer, data, length);
return nbytes == length; return nbytes == length;
} }
if (normal_buffer == nullptr) if (normal_buffer == nullptr)
normal_buffer = new DynamicFifoBuffer<uint8_t>(normal_size); normal_buffer = new DynamicFifoBuffer<uint8_t>(normal_size);
size_t nbytes = AppendTo(*normal_buffer, data, length); std::size_t nbytes = AppendTo(*normal_buffer, data, length);
if (nbytes > 0) { if (nbytes > 0) {
data = (const uint8_t *)data + nbytes; data = (const uint8_t *)data + nbytes;
length -= nbytes; length -= nbytes;

View File

@ -34,12 +34,12 @@ template<typename T> class DynamicFifoBuffer;
* kernel when it has been consumed. * kernel when it has been consumed.
*/ */
class PeakBuffer { class PeakBuffer {
size_t normal_size, peak_size; std::size_t normal_size, peak_size;
DynamicFifoBuffer<uint8_t> *normal_buffer, *peak_buffer; DynamicFifoBuffer<uint8_t> *normal_buffer, *peak_buffer;
public: public:
PeakBuffer(size_t _normal_size, size_t _peak_size) PeakBuffer(std::size_t _normal_size, std::size_t _peak_size)
:normal_size(_normal_size), peak_size(_peak_size), :normal_size(_normal_size), peak_size(_peak_size),
normal_buffer(nullptr), peak_buffer(nullptr) {} normal_buffer(nullptr), peak_buffer(nullptr) {}
@ -62,9 +62,9 @@ public:
gcc_pure gcc_pure
WritableBuffer<void> Read() const noexcept; WritableBuffer<void> Read() const noexcept;
void Consume(size_t length) noexcept; void Consume(std::size_t length) noexcept;
bool Append(const void *data, size_t length); bool Append(const void *data, std::size_t length);
}; };
#endif #endif