tag/Id3Load, ...: use std::make_unique_for_overwrite()

Don't zero-initialize the buffers.  This removes some useless
overhead.
This commit is contained in:
Max Kellermann 2025-01-29 11:52:35 +01:00
parent a5da7fd51a
commit 57e7fb3f62
10 changed files with 13 additions and 13 deletions

@ -191,7 +191,7 @@ read_stream_art(Response &r, const std::string_view art_directory,
std::min<offset_type>(art_file_size - offset,
r.GetClient().binary_limit);
auto buffer = std::make_unique<std::byte[]>(buffer_size);
auto buffer = std::make_unique_for_overwrite<std::byte[]>(buffer_size);
std::size_t read_size = 0;
if (buffer_size > 0) {

@ -266,7 +266,7 @@ MadDecoder::ParseId3(size_t tagsize, Tag *mpd_tag) noexcept
id3_data = stream.this_frame;
mad_stream_skip(&(stream), tagsize);
} else {
allocated = std::make_unique<id3_byte_t[]>(tagsize);
allocated = std::make_unique_for_overwrite<id3_byte_t[]>(tagsize);
memcpy(allocated.get(), stream.this_frame, count);
mad_stream_skip(&(stream), count);

@ -101,7 +101,7 @@ SidplayGlobal::SidplayGlobal(const ConfigBlock &block)
const auto kernal_path = block.GetPath("kernal");
if (!kernal_path.IsNull())
{
kernal = std::make_unique<uint8_t[]>(rom_size);
kernal = std::make_unique_for_overwrite<uint8_t[]>(rom_size);
loadRom(kernal_path, kernal.get());
}
@ -109,7 +109,7 @@ SidplayGlobal::SidplayGlobal(const ConfigBlock &block)
const auto basic_path = block.GetPath("basic");
if (!basic_path.IsNull())
{
basic = std::make_unique<uint8_t[]>(rom_size);
basic = std::make_unique_for_overwrite<uint8_t[]>(rom_size);
loadRom(basic_path, basic.get());
}
}

@ -17,7 +17,7 @@ ReadOperation::Start(Queue &queue, FileDescriptor fd, off_t offset,
handler = &_handler;
buffer = std::make_unique<std::byte[]>(size);
buffer = std::make_unique_for_overwrite<std::byte[]>(size);
auto &s = queue.RequireSubmitEntry();

@ -38,7 +38,7 @@ UCharToUTF8(std::basic_string_view<UChar> src)
/* worst-case estimate */
size_t dest_capacity = 4 * src.size();
auto dest = std::make_unique<char[]>(dest_capacity + 1);
auto dest = std::make_unique_for_overwrite<char[]>(dest_capacity + 1);
UErrorCode error_code = U_ZERO_ERROR;
int32_t dest_length;

@ -18,7 +18,7 @@ WideCharToMultiByte(unsigned code_page, std::wstring_view src)
if (length <= 0)
throw MakeLastError("Failed to convert from Unicode");
auto buffer = std::make_unique<char[]>(length + 1);
auto buffer = std::make_unique_for_overwrite<char[]>(length + 1);
length = WideCharToMultiByte(code_page, 0, src.data(), src.size(),
buffer.get(), length,
nullptr, nullptr);
@ -37,7 +37,7 @@ MultiByteToWideChar(unsigned code_page, std::string_view src)
if (length <= 0)
throw MakeLastError("Failed to convert to Unicode");
auto buffer = std::make_unique<wchar_t[]>(length + 1);
auto buffer = std::make_unique_for_overwrite<wchar_t[]>(length + 1);
length = MultiByteToWideChar(code_page, 0, src.data(), src.size(),
buffer.get(), length);
if (length <= 0)

@ -148,7 +148,7 @@ NfsFileReader::Read(uint64_t offset, size_t size)
#ifdef LIBNFS_API_2
assert(!read_buffer);
// TOOD read into caller-provided buffer
read_buffer = std::make_unique<std::byte[]>(size);
read_buffer = std::make_unique_for_overwrite<std::byte[]>(size);
connection->Read(fh, offset, {read_buffer.get(), size}, *this);
#else
connection->Read(fh, offset, size, *this);

@ -147,7 +147,7 @@ Queue::MovePostion(unsigned from, unsigned to) noexcept
void
Queue::MoveRange(unsigned start, unsigned end, unsigned to) noexcept
{
const auto tmp = std::make_unique<Item[]>(end - start);
const auto tmp = std::make_unique_for_overwrite<Item[]>(end - start);
// Copy the original block [start,end-1]
for (unsigned i = start; i < end; i++)

@ -50,7 +50,7 @@ try {
remaining -= sizeof(footer);
assert(remaining > 10);
auto buffer = std::make_unique<std::byte[]>(remaining);
auto buffer = std::make_unique_for_overwrite<std::byte[]>(remaining);
is.ReadFull(lock, {buffer.get(), remaining});
/* read tags */

@ -47,7 +47,7 @@ try {
/* we have enough data already */
return UniqueId3Tag(id3_tag_parse(query_buffer, tag_size));
auto tag_buffer = std::make_unique<id3_byte_t[]>(tag_size);
auto tag_buffer = std::make_unique_for_overwrite<id3_byte_t[]>(tag_size);
/* copy the start of the tag we already have to the allocated
buffer */
@ -182,7 +182,7 @@ try {
/* too large, don't allocate so much memory */
return nullptr;
auto buffer = std::make_unique<id3_byte_t[]>(size);
auto buffer = std::make_unique_for_overwrite<id3_byte_t[]>(size);
is.ReadFull(lock, std::as_writable_bytes(std::span{buffer.get(), size}));
return UniqueId3Tag(id3_tag_parse(buffer.get(), size));