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

View File

@@ -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;

View File

@@ -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)

View File

@@ -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);