util/PeakBuffer: use std::byte instead of std::uint8_t

This commit is contained in:
Max Kellermann 2021-01-21 16:43:20 +01:00
parent fa82f558be
commit eea0e084af
2 changed files with 6 additions and 7 deletions

View File

@ -76,7 +76,7 @@ PeakBuffer::Consume(std::size_t length) noexcept
}
static std::size_t
AppendTo(DynamicFifoBuffer<uint8_t> &buffer,
AppendTo(DynamicFifoBuffer<std::byte> &buffer,
const void *data, size_t length) noexcept
{
assert(data != nullptr);
@ -93,7 +93,7 @@ AppendTo(DynamicFifoBuffer<uint8_t> &buffer,
memcpy(p.data, data, nbytes);
buffer.Append(nbytes);
data = (const uint8_t *)data + nbytes;
data = (const std::byte *)data + nbytes;
length -= nbytes;
total += nbytes;
} while (length > 0);
@ -113,11 +113,11 @@ PeakBuffer::Append(const void *data, std::size_t length)
}
if (normal_buffer == nullptr)
normal_buffer = new DynamicFifoBuffer<uint8_t>(normal_size);
normal_buffer = new DynamicFifoBuffer<std::byte>(normal_size);
std::size_t nbytes = AppendTo(*normal_buffer, data, length);
if (nbytes > 0) {
data = (const uint8_t *)data + nbytes;
data = (const std::byte *)data + nbytes;
length -= nbytes;
if (length == 0)
return true;
@ -125,7 +125,7 @@ PeakBuffer::Append(const void *data, std::size_t length)
if (peak_buffer == nullptr) {
if (peak_size > 0)
peak_buffer = new DynamicFifoBuffer<uint8_t>(peak_size);
peak_buffer = new DynamicFifoBuffer<std::byte>(peak_size);
if (peak_buffer == nullptr)
return false;
}

View File

@ -23,7 +23,6 @@
#include "Compiler.h"
#include <cstddef>
#include <cstdint>
template<typename T> struct WritableBuffer;
template<typename T> class DynamicFifoBuffer;
@ -36,7 +35,7 @@ template<typename T> class DynamicFifoBuffer;
class PeakBuffer {
std::size_t normal_size, peak_size;
DynamicFifoBuffer<uint8_t> *normal_buffer, *peak_buffer;
DynamicFifoBuffer<std::byte> *normal_buffer, *peak_buffer;
public:
PeakBuffer(std::size_t _normal_size, std::size_t _peak_size) noexcept