util/PeakBuffer: use std::size_t
This commit is contained in:
parent
dafba203e7
commit
6b555b7017
|
@ -57,7 +57,7 @@ PeakBuffer::Read() const noexcept
|
|||
}
|
||||
|
||||
void
|
||||
PeakBuffer::Consume(size_t length) noexcept
|
||||
PeakBuffer::Consume(std::size_t length) noexcept
|
||||
{
|
||||
if (normal_buffer != nullptr && !normal_buffer->empty()) {
|
||||
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,
|
||||
const void *data, size_t length) noexcept
|
||||
{
|
||||
assert(data != nullptr);
|
||||
assert(length > 0);
|
||||
|
||||
size_t total = 0;
|
||||
std::size_t total = 0;
|
||||
|
||||
do {
|
||||
const auto p = buffer.Write();
|
||||
if (p.empty())
|
||||
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);
|
||||
buffer.Append(nbytes);
|
||||
|
||||
|
@ -102,20 +102,20 @@ AppendTo(DynamicFifoBuffer<uint8_t> &buffer,
|
|||
}
|
||||
|
||||
bool
|
||||
PeakBuffer::Append(const void *data, size_t length)
|
||||
PeakBuffer::Append(const void *data, std::size_t length)
|
||||
{
|
||||
if (length == 0)
|
||||
return true;
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
if (normal_buffer == nullptr)
|
||||
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) {
|
||||
data = (const uint8_t *)data + nbytes;
|
||||
length -= nbytes;
|
||||
|
|
|
@ -34,12 +34,12 @@ template<typename T> class DynamicFifoBuffer;
|
|||
* kernel when it has been consumed.
|
||||
*/
|
||||
class PeakBuffer {
|
||||
size_t normal_size, peak_size;
|
||||
std::size_t normal_size, peak_size;
|
||||
|
||||
DynamicFifoBuffer<uint8_t> *normal_buffer, *peak_buffer;
|
||||
|
||||
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_buffer(nullptr), peak_buffer(nullptr) {}
|
||||
|
||||
|
@ -62,9 +62,9 @@ public:
|
|||
gcc_pure
|
||||
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
|
||||
|
|
Loading…
Reference in New Issue