Skip to content

Commit 57e7fb3

Browse files
committed
tag/Id3Load, ...: use std::make_unique_for_overwrite()
Don't zero-initialize the buffers. This removes some useless overhead.
1 parent a5da7fd commit 57e7fb3

File tree

10 files changed

+13
-13
lines changed

10 files changed

+13
-13
lines changed

src/command/FileCommands.cxx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,7 @@ read_stream_art(Response &r, const std::string_view art_directory,
191191
std::min<offset_type>(art_file_size - offset,
192192
r.GetClient().binary_limit);
193193

194-
auto buffer = std::make_unique<std::byte[]>(buffer_size);
194+
auto buffer = std::make_unique_for_overwrite<std::byte[]>(buffer_size);
195195

196196
std::size_t read_size = 0;
197197
if (buffer_size > 0) {

src/decoder/plugins/MadDecoderPlugin.cxx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -266,7 +266,7 @@ MadDecoder::ParseId3(size_t tagsize, Tag *mpd_tag) noexcept
266266
id3_data = stream.this_frame;
267267
mad_stream_skip(&(stream), tagsize);
268268
} else {
269-
allocated = std::make_unique<id3_byte_t[]>(tagsize);
269+
allocated = std::make_unique_for_overwrite<id3_byte_t[]>(tagsize);
270270
memcpy(allocated.get(), stream.this_frame, count);
271271
mad_stream_skip(&(stream), count);
272272

src/decoder/plugins/SidplayDecoderPlugin.cxx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -101,15 +101,15 @@ SidplayGlobal::SidplayGlobal(const ConfigBlock &block)
101101
const auto kernal_path = block.GetPath("kernal");
102102
if (!kernal_path.IsNull())
103103
{
104-
kernal = std::make_unique<uint8_t[]>(rom_size);
104+
kernal = std::make_unique_for_overwrite<uint8_t[]>(rom_size);
105105
loadRom(kernal_path, kernal.get());
106106
}
107107

108108
/* read basic rom dump file */
109109
const auto basic_path = block.GetPath("basic");
110110
if (!basic_path.IsNull())
111111
{
112-
basic = std::make_unique<uint8_t[]>(rom_size);
112+
basic = std::make_unique_for_overwrite<uint8_t[]>(rom_size);
113113
loadRom(basic_path, basic.get());
114114
}
115115
}

src/io/uring/ReadOperation.cxx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ ReadOperation::Start(Queue &queue, FileDescriptor fd, off_t offset,
1717

1818
handler = &_handler;
1919

20-
buffer = std::make_unique<std::byte[]>(size);
20+
buffer = std::make_unique_for_overwrite<std::byte[]>(size);
2121

2222
auto &s = queue.RequireSubmitEntry();
2323

src/lib/icu/Util.cxx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ UCharToUTF8(std::basic_string_view<UChar> src)
3838
/* worst-case estimate */
3939
size_t dest_capacity = 4 * src.size();
4040

41-
auto dest = std::make_unique<char[]>(dest_capacity + 1);
41+
auto dest = std::make_unique_for_overwrite<char[]>(dest_capacity + 1);
4242

4343
UErrorCode error_code = U_ZERO_ERROR;
4444
int32_t dest_length;

src/lib/icu/Win32.cxx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ WideCharToMultiByte(unsigned code_page, std::wstring_view src)
1818
if (length <= 0)
1919
throw MakeLastError("Failed to convert from Unicode");
2020

21-
auto buffer = std::make_unique<char[]>(length + 1);
21+
auto buffer = std::make_unique_for_overwrite<char[]>(length + 1);
2222
length = WideCharToMultiByte(code_page, 0, src.data(), src.size(),
2323
buffer.get(), length,
2424
nullptr, nullptr);
@@ -37,7 +37,7 @@ MultiByteToWideChar(unsigned code_page, std::string_view src)
3737
if (length <= 0)
3838
throw MakeLastError("Failed to convert to Unicode");
3939

40-
auto buffer = std::make_unique<wchar_t[]>(length + 1);
40+
auto buffer = std::make_unique_for_overwrite<wchar_t[]>(length + 1);
4141
length = MultiByteToWideChar(code_page, 0, src.data(), src.size(),
4242
buffer.get(), length);
4343
if (length <= 0)

src/lib/nfs/FileReader.cxx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@ NfsFileReader::Read(uint64_t offset, size_t size)
148148
#ifdef LIBNFS_API_2
149149
assert(!read_buffer);
150150
// TOOD read into caller-provided buffer
151-
read_buffer = std::make_unique<std::byte[]>(size);
151+
read_buffer = std::make_unique_for_overwrite<std::byte[]>(size);
152152
connection->Read(fh, offset, {read_buffer.get(), size}, *this);
153153
#else
154154
connection->Read(fh, offset, size, *this);

src/queue/Queue.cxx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ Queue::MovePostion(unsigned from, unsigned to) noexcept
147147
void
148148
Queue::MoveRange(unsigned start, unsigned end, unsigned to) noexcept
149149
{
150-
const auto tmp = std::make_unique<Item[]>(end - start);
150+
const auto tmp = std::make_unique_for_overwrite<Item[]>(end - start);
151151

152152
// Copy the original block [start,end-1]
153153
for (unsigned i = start; i < end; i++)

src/tag/ApeLoader.cxx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ try {
5050
remaining -= sizeof(footer);
5151
assert(remaining > 10);
5252

53-
auto buffer = std::make_unique<std::byte[]>(remaining);
53+
auto buffer = std::make_unique_for_overwrite<std::byte[]>(remaining);
5454
is.ReadFull(lock, {buffer.get(), remaining});
5555

5656
/* read tags */

src/tag/Id3Load.cxx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ try {
4747
/* we have enough data already */
4848
return UniqueId3Tag(id3_tag_parse(query_buffer, tag_size));
4949

50-
auto tag_buffer = std::make_unique<id3_byte_t[]>(tag_size);
50+
auto tag_buffer = std::make_unique_for_overwrite<id3_byte_t[]>(tag_size);
5151

5252
/* copy the start of the tag we already have to the allocated
5353
buffer */
@@ -182,7 +182,7 @@ try {
182182
/* too large, don't allocate so much memory */
183183
return nullptr;
184184

185-
auto buffer = std::make_unique<id3_byte_t[]>(size);
185+
auto buffer = std::make_unique_for_overwrite<id3_byte_t[]>(size);
186186
is.ReadFull(lock, std::as_writable_bytes(std::span{buffer.get(), size}));
187187

188188
return UniqueId3Tag(id3_tag_parse(buffer.get(), size));

0 commit comments

Comments
 (0)