From 31aa6d0c4fc56752586f5226ed9426a52ca93f69 Mon Sep 17 00:00:00 2001 From: Rosen Penev Date: Thu, 11 Nov 2021 00:47:45 -0800 Subject: [PATCH] use auto with make_unique C arrays can be used with make_unique in C++17. Signed-off-by: Rosen Penev --- src/command/FileCommands.cxx | 2 +- src/decoder/plugins/MadDecoderPlugin.cxx | 2 +- src/decoder/plugins/SidplayDecoderPlugin.cxx | 4 ++-- src/lib/icu/Util.cxx | 2 +- src/lib/xiph/VorbisPicture.cxx | 3 +-- src/output/plugins/OSXOutputPlugin.cxx | 2 +- src/tag/ApeLoader.cxx | 2 +- src/tag/Id3Load.cxx | 4 ++-- 8 files changed, 10 insertions(+), 11 deletions(-) diff --git a/src/command/FileCommands.cxx b/src/command/FileCommands.cxx index c66a62413..006dedf28 100644 --- a/src/command/FileCommands.cxx +++ b/src/command/FileCommands.cxx @@ -213,7 +213,7 @@ read_stream_art(Response &r, const std::string_view art_directory, std::min(art_file_size - offset, r.GetClient().binary_limit); - std::unique_ptr buffer(new std::byte[buffer_size]); + auto buffer = std::make_unique(buffer_size); std::size_t read_size = 0; if (buffer_size > 0) { diff --git a/src/decoder/plugins/MadDecoderPlugin.cxx b/src/decoder/plugins/MadDecoderPlugin.cxx index e1a2f0cf6..98d48e2a6 100644 --- a/src/decoder/plugins/MadDecoderPlugin.cxx +++ b/src/decoder/plugins/MadDecoderPlugin.cxx @@ -310,7 +310,7 @@ MadDecoder::ParseId3(size_t tagsize, Tag *mpd_tag) noexcept id3_data = stream.this_frame; mad_stream_skip(&(stream), tagsize); } else { - allocated.reset(new id3_byte_t[tagsize]); + allocated = std::make_unique(tagsize); memcpy(allocated.get(), stream.this_frame, count); mad_stream_skip(&(stream), count); diff --git a/src/decoder/plugins/SidplayDecoderPlugin.cxx b/src/decoder/plugins/SidplayDecoderPlugin.cxx index 3dc2fb156..3aff1b4f6 100644 --- a/src/decoder/plugins/SidplayDecoderPlugin.cxx +++ b/src/decoder/plugins/SidplayDecoderPlugin.cxx @@ -137,7 +137,7 @@ SidplayGlobal::SidplayGlobal(const ConfigBlock &block) const auto kernal_path = block.GetPath("kernal"); if (!kernal_path.IsNull()) { - kernal.reset(new uint8_t[rom_size]); + kernal = std::make_unique(rom_size); loadRom(kernal_path, kernal.get()); } @@ -145,7 +145,7 @@ SidplayGlobal::SidplayGlobal(const ConfigBlock &block) const auto basic_path = block.GetPath("basic"); if (!basic_path.IsNull()) { - basic.reset(new uint8_t[rom_size]); + basic = std::make_unique(rom_size); loadRom(basic_path, basic.get()); } #endif diff --git a/src/lib/icu/Util.cxx b/src/lib/icu/Util.cxx index a473f987b..4739c3f45 100644 --- a/src/lib/icu/Util.cxx +++ b/src/lib/icu/Util.cxx @@ -54,7 +54,7 @@ UCharToUTF8(std::basic_string_view src) /* worst-case estimate */ size_t dest_capacity = 4 * src.size(); - std::unique_ptr dest(new char[dest_capacity + 1]); + auto dest = std::make_unique(dest_capacity + 1); UErrorCode error_code = U_ZERO_ERROR; int32_t dest_length; diff --git a/src/lib/xiph/VorbisPicture.cxx b/src/lib/xiph/VorbisPicture.cxx index 3d7027234..51df21390 100644 --- a/src/lib/xiph/VorbisPicture.cxx +++ b/src/lib/xiph/VorbisPicture.cxx @@ -36,8 +36,7 @@ ScanVorbisPicture(StringView value, TagHandler &handler) noexcept return; size_t debase64_size = CalculateBase64OutputSize(value.size); - std::unique_ptr debase64_buffer; - debase64_buffer.reset(new uint8_t[debase64_size]); + auto debase64_buffer = std::make_unique(debase64_size); try { debase64_size = diff --git a/src/output/plugins/OSXOutputPlugin.cxx b/src/output/plugins/OSXOutputPlugin.cxx index c8eb1da23..5dafee2cd 100644 --- a/src/output/plugins/OSXOutputPlugin.cxx +++ b/src/output/plugins/OSXOutputPlugin.cxx @@ -291,7 +291,7 @@ osx_output_set_channel_map(OSXOutput *oo) OSStatus status; const UInt32 num_channels = AudioUnitGetChannelsPerFrame(oo->au); - std::unique_ptr channel_map(new SInt32[num_channels]); + auto channel_map = std::make_unique(num_channels); osx_output_parse_channel_map(oo->device_name, oo->channel_map, channel_map.get(), diff --git a/src/tag/ApeLoader.cxx b/src/tag/ApeLoader.cxx index 596ac8201..16837fb4c 100644 --- a/src/tag/ApeLoader.cxx +++ b/src/tag/ApeLoader.cxx @@ -66,7 +66,7 @@ try { remaining -= sizeof(footer); assert(remaining > 10); - std::unique_ptr buffer(new char[remaining]); + auto buffer = std::make_unique(remaining); is.ReadFull(lock, buffer.get(), remaining); /* read tags */ diff --git a/src/tag/Id3Load.cxx b/src/tag/Id3Load.cxx index 69a4381f0..68658103e 100644 --- a/src/tag/Id3Load.cxx +++ b/src/tag/Id3Load.cxx @@ -63,7 +63,7 @@ try { /* we have enough data already */ return UniqueId3Tag(id3_tag_parse(query_buffer, tag_size)); - std::unique_ptr tag_buffer(new id3_byte_t[tag_size]); + auto tag_buffer = std::make_unique(tag_size); /* copy the start of the tag we already have to the allocated buffer */ @@ -198,7 +198,7 @@ try { /* too large, don't allocate so much memory */ return nullptr; - std::unique_ptr buffer(new id3_byte_t[size]); + auto buffer = std::make_unique(size); is.ReadFull(lock, buffer.get(), size); return UniqueId3Tag(id3_tag_parse(buffer.get(), size));