tag/Id3Load, ...: use std::make_unique_for_overwrite()
Don't zero-initialize the buffers. This removes some useless overhead.
This commit is contained in:
src
command
decoder
io
uring
lib
queue
tag
@ -191,7 +191,7 @@ read_stream_art(Response &r, const std::string_view art_directory,
|
|||||||
std::min<offset_type>(art_file_size - offset,
|
std::min<offset_type>(art_file_size - offset,
|
||||||
r.GetClient().binary_limit);
|
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;
|
std::size_t read_size = 0;
|
||||||
if (buffer_size > 0) {
|
if (buffer_size > 0) {
|
||||||
|
@ -266,7 +266,7 @@ MadDecoder::ParseId3(size_t tagsize, Tag *mpd_tag) noexcept
|
|||||||
id3_data = stream.this_frame;
|
id3_data = stream.this_frame;
|
||||||
mad_stream_skip(&(stream), tagsize);
|
mad_stream_skip(&(stream), tagsize);
|
||||||
} else {
|
} 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);
|
memcpy(allocated.get(), stream.this_frame, count);
|
||||||
mad_stream_skip(&(stream), count);
|
mad_stream_skip(&(stream), count);
|
||||||
|
|
||||||
|
@ -101,7 +101,7 @@ SidplayGlobal::SidplayGlobal(const ConfigBlock &block)
|
|||||||
const auto kernal_path = block.GetPath("kernal");
|
const auto kernal_path = block.GetPath("kernal");
|
||||||
if (!kernal_path.IsNull())
|
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());
|
loadRom(kernal_path, kernal.get());
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -109,7 +109,7 @@ SidplayGlobal::SidplayGlobal(const ConfigBlock &block)
|
|||||||
const auto basic_path = block.GetPath("basic");
|
const auto basic_path = block.GetPath("basic");
|
||||||
if (!basic_path.IsNull())
|
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());
|
loadRom(basic_path, basic.get());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -17,7 +17,7 @@ ReadOperation::Start(Queue &queue, FileDescriptor fd, off_t offset,
|
|||||||
|
|
||||||
handler = &_handler;
|
handler = &_handler;
|
||||||
|
|
||||||
buffer = std::make_unique<std::byte[]>(size);
|
buffer = std::make_unique_for_overwrite<std::byte[]>(size);
|
||||||
|
|
||||||
auto &s = queue.RequireSubmitEntry();
|
auto &s = queue.RequireSubmitEntry();
|
||||||
|
|
||||||
|
@ -38,7 +38,7 @@ UCharToUTF8(std::basic_string_view<UChar> src)
|
|||||||
/* worst-case estimate */
|
/* worst-case estimate */
|
||||||
size_t dest_capacity = 4 * src.size();
|
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;
|
UErrorCode error_code = U_ZERO_ERROR;
|
||||||
int32_t dest_length;
|
int32_t dest_length;
|
||||||
|
@ -18,7 +18,7 @@ WideCharToMultiByte(unsigned code_page, std::wstring_view src)
|
|||||||
if (length <= 0)
|
if (length <= 0)
|
||||||
throw MakeLastError("Failed to convert from Unicode");
|
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(),
|
length = WideCharToMultiByte(code_page, 0, src.data(), src.size(),
|
||||||
buffer.get(), length,
|
buffer.get(), length,
|
||||||
nullptr, nullptr);
|
nullptr, nullptr);
|
||||||
@ -37,7 +37,7 @@ MultiByteToWideChar(unsigned code_page, std::string_view src)
|
|||||||
if (length <= 0)
|
if (length <= 0)
|
||||||
throw MakeLastError("Failed to convert to Unicode");
|
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(),
|
length = MultiByteToWideChar(code_page, 0, src.data(), src.size(),
|
||||||
buffer.get(), length);
|
buffer.get(), length);
|
||||||
if (length <= 0)
|
if (length <= 0)
|
||||||
|
@ -148,7 +148,7 @@ NfsFileReader::Read(uint64_t offset, size_t size)
|
|||||||
#ifdef LIBNFS_API_2
|
#ifdef LIBNFS_API_2
|
||||||
assert(!read_buffer);
|
assert(!read_buffer);
|
||||||
// TOOD read into caller-provided 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);
|
connection->Read(fh, offset, {read_buffer.get(), size}, *this);
|
||||||
#else
|
#else
|
||||||
connection->Read(fh, offset, size, *this);
|
connection->Read(fh, offset, size, *this);
|
||||||
|
@ -147,7 +147,7 @@ Queue::MovePostion(unsigned from, unsigned to) noexcept
|
|||||||
void
|
void
|
||||||
Queue::MoveRange(unsigned start, unsigned end, unsigned to) noexcept
|
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]
|
// Copy the original block [start,end-1]
|
||||||
for (unsigned i = start; i < end; i++)
|
for (unsigned i = start; i < end; i++)
|
||||||
|
@ -50,7 +50,7 @@ try {
|
|||||||
remaining -= sizeof(footer);
|
remaining -= sizeof(footer);
|
||||||
assert(remaining > 10);
|
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});
|
is.ReadFull(lock, {buffer.get(), remaining});
|
||||||
|
|
||||||
/* read tags */
|
/* read tags */
|
||||||
|
@ -47,7 +47,7 @@ try {
|
|||||||
/* we have enough data already */
|
/* we have enough data already */
|
||||||
return UniqueId3Tag(id3_tag_parse(query_buffer, tag_size));
|
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
|
/* copy the start of the tag we already have to the allocated
|
||||||
buffer */
|
buffer */
|
||||||
@ -182,7 +182,7 @@ try {
|
|||||||
/* too large, don't allocate so much memory */
|
/* too large, don't allocate so much memory */
|
||||||
return nullptr;
|
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}));
|
is.ReadFull(lock, std::as_writable_bytes(std::span{buffer.get(), size}));
|
||||||
|
|
||||||
return UniqueId3Tag(id3_tag_parse(buffer.get(), size));
|
return UniqueId3Tag(id3_tag_parse(buffer.get(), size));
|
||||||
|
Reference in New Issue
Block a user