From a1a01e21cf828689c411c64f98fe72af04a9a545 Mon Sep 17 00:00:00 2001 From: Peter Nelson Date: Sat, 20 Apr 2024 11:20:49 +0100 Subject: [PATCH] Change: Use std::make_unique instead of passing new() (#12539) --- src/gfx_layout_fallback.cpp | 2 +- src/gfx_layout_icu.cpp | 2 +- src/openttd.cpp | 2 +- src/os/macosx/string_osx.cpp | 3 ++- src/os/windows/string_uniscribe.cpp | 2 +- src/spriteloader/grf.cpp | 2 +- 6 files changed, 7 insertions(+), 6 deletions(-) diff --git a/src/gfx_layout_fallback.cpp b/src/gfx_layout_fallback.cpp index 745a834c1f..2b8fc617eb 100644 --- a/src/gfx_layout_fallback.cpp +++ b/src/gfx_layout_fallback.cpp @@ -218,7 +218,7 @@ std::unique_ptr FallbackParagraphLayout::NextLine */ if (this->buffer == nullptr) return nullptr; - std::unique_ptr l(new FallbackLine()); + std::unique_ptr l = std::make_unique(); if (*this->buffer == '\0') { /* Only a newline. */ diff --git a/src/gfx_layout_icu.cpp b/src/gfx_layout_icu.cpp index de9dae6c91..1e53d15c8a 100644 --- a/src/gfx_layout_icu.cpp +++ b/src/gfx_layout_icu.cpp @@ -489,7 +489,7 @@ std::unique_ptr ICUParagraphLayout::NextLine(int ubidi_reorderVisual(bidi_level.data(), bidi_level.size(), vis_to_log.data()); /* Create line. */ - std::unique_ptr line(new ICULine()); + std::unique_ptr line = std::make_unique(); int cur_pos = 0; for (auto &i : vis_to_log) { diff --git a/src/openttd.cpp b/src/openttd.cpp index 5b53be6dd6..0d9ef39c0d 100644 --- a/src/openttd.cpp +++ b/src/openttd.cpp @@ -517,7 +517,7 @@ int openttd_main(std::span arguments) std::string sounds_set; std::string music_set; Dimension resolution = {0, 0}; - std::unique_ptr scanner(new AfterNewGRFScan()); + std::unique_ptr scanner = std::make_unique(); bool dedicated = false; bool only_local_path = false; diff --git a/src/os/macosx/string_osx.cpp b/src/os/macosx/string_osx.cpp index 539d478a4e..6a7a45285e 100644 --- a/src/os/macosx/string_osx.cpp +++ b/src/os/macosx/string_osx.cpp @@ -224,7 +224,8 @@ static CTRunDelegateCallbacks _sprite_font_callback = { CFAutoRelease line(CTTypesetterCreateLine(this->typesetter.get(), CFRangeMake(this->cur_offset, len))); this->cur_offset += len; - return std::unique_ptr(line ? new CoreTextLine(std::move(line), this->font_map, this->text_buffer) : nullptr); + if (!line) return nullptr; + return std::make_unique(std::move(line), this->font_map, this->text_buffer); } CoreTextParagraphLayout::CoreTextVisualRun::CoreTextVisualRun(CTRunRef run, Font *font, const CoreTextParagraphLayoutFactory::CharType *buff) : font(font) diff --git a/src/os/windows/string_uniscribe.cpp b/src/os/windows/string_uniscribe.cpp index 5e2b4019d5..3045d694f3 100644 --- a/src/os/windows/string_uniscribe.cpp +++ b/src/os/windows/string_uniscribe.cpp @@ -405,7 +405,7 @@ static std::vector UniscribeItemizeString(UniscribeParagraphLayoutF if (FAILED(ScriptLayout((int)bidi_level.size(), &bidi_level[0], &vis_to_log[0], nullptr))) return nullptr; /* Create line. */ - std::unique_ptr line(new UniscribeLine()); + std::unique_ptr line = std::make_unique(); int cur_pos = 0; for (std::vector::iterator l = vis_to_log.begin(); l != vis_to_log.end(); l++) { diff --git a/src/spriteloader/grf.cpp b/src/spriteloader/grf.cpp index d365282d2a..62580ad6a8 100644 --- a/src/spriteloader/grf.cpp +++ b/src/spriteloader/grf.cpp @@ -68,7 +68,7 @@ bool DecodeSingleSprite(SpriteLoader::Sprite *sprite, SpriteFile &file, size_t f */ if (num < 0 || num > 64 * 1024 * 1024) return WarnCorruptSprite(file, file_pos, __LINE__); - std::unique_ptr dest_orig(new uint8_t[num]); + std::unique_ptr dest_orig = std::make_unique(num); uint8_t *dest = dest_orig.get(); const int64_t dest_size = num;