Skip to content

Commit

Permalink
Change: Use std::make_unique instead of passing new() (#12539)
Browse files Browse the repository at this point in the history
  • Loading branch information
PeterN committed Apr 20, 2024
1 parent fc7f184 commit a1a01e2
Show file tree
Hide file tree
Showing 6 changed files with 7 additions and 6 deletions.
2 changes: 1 addition & 1 deletion src/gfx_layout_fallback.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,7 @@ std::unique_ptr<const ParagraphLayouter::Line> FallbackParagraphLayout::NextLine
*/
if (this->buffer == nullptr) return nullptr;

std::unique_ptr<FallbackLine> l(new FallbackLine());
std::unique_ptr<FallbackLine> l = std::make_unique<FallbackLine>();

if (*this->buffer == '\0') {
/* Only a newline. */
Expand Down
2 changes: 1 addition & 1 deletion src/gfx_layout_icu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -489,7 +489,7 @@ std::unique_ptr<const ICUParagraphLayout::Line> ICUParagraphLayout::NextLine(int
ubidi_reorderVisual(bidi_level.data(), bidi_level.size(), vis_to_log.data());

/* Create line. */
std::unique_ptr<ICULine> line(new ICULine());
std::unique_ptr<ICULine> line = std::make_unique<ICULine>();

int cur_pos = 0;
for (auto &i : vis_to_log) {
Expand Down
2 changes: 1 addition & 1 deletion src/openttd.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -517,7 +517,7 @@ int openttd_main(std::span<char * const> arguments)
std::string sounds_set;
std::string music_set;
Dimension resolution = {0, 0};
std::unique_ptr<AfterNewGRFScan> scanner(new AfterNewGRFScan());
std::unique_ptr<AfterNewGRFScan> scanner = std::make_unique<AfterNewGRFScan>();
bool dedicated = false;
bool only_local_path = false;

Expand Down
3 changes: 2 additions & 1 deletion src/os/macosx/string_osx.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,8 @@ static CTRunDelegateCallbacks _sprite_font_callback = {
CFAutoRelease<CTLineRef> line(CTTypesetterCreateLine(this->typesetter.get(), CFRangeMake(this->cur_offset, len)));
this->cur_offset += len;

return std::unique_ptr<const Line>(line ? new CoreTextLine(std::move(line), this->font_map, this->text_buffer) : nullptr);
if (!line) return nullptr;
return std::make_unique<CoreTextLine>(std::move(line), this->font_map, this->text_buffer);
}

CoreTextParagraphLayout::CoreTextVisualRun::CoreTextVisualRun(CTRunRef run, Font *font, const CoreTextParagraphLayoutFactory::CharType *buff) : font(font)
Expand Down
2 changes: 1 addition & 1 deletion src/os/windows/string_uniscribe.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -405,7 +405,7 @@ static std::vector<SCRIPT_ITEM> UniscribeItemizeString(UniscribeParagraphLayoutF
if (FAILED(ScriptLayout((int)bidi_level.size(), &bidi_level[0], &vis_to_log[0], nullptr))) return nullptr;

/* Create line. */
std::unique_ptr<UniscribeLine> line(new UniscribeLine());
std::unique_ptr<UniscribeLine> line = std::make_unique<UniscribeLine>();

int cur_pos = 0;
for (std::vector<INT>::iterator l = vis_to_log.begin(); l != vis_to_log.end(); l++) {
Expand Down
2 changes: 1 addition & 1 deletion src/spriteloader/grf.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<uint8_t[]> dest_orig(new uint8_t[num]);
std::unique_ptr<uint8_t[]> dest_orig = std::make_unique<uint8_t[]>(num);
uint8_t *dest = dest_orig.get();
const int64_t dest_size = num;

Expand Down

0 comments on commit a1a01e2

Please sign in to comment.