Codefix: Avoiding passing new raw pointer into a smart pointer. (#13138)

Use `std::make_shared` or `std::make_unique` instead of `reset(new ...)`.
This commit is contained in:
Peter Nelson 2024-12-01 14:22:41 +00:00 committed by GitHub
parent 46176a81e3
commit e28617fda6
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 4 additions and 4 deletions

View File

@ -370,7 +370,7 @@ bool GraphicsSet::FillSetDetails(const IniFile &ini, const std::string &path, co
GRFConfig &GraphicsSet::GetOrCreateExtraConfig() const GRFConfig &GraphicsSet::GetOrCreateExtraConfig() const
{ {
if (!this->extra_cfg) { if (!this->extra_cfg) {
this->extra_cfg.reset(new GRFConfig(this->files[GFT_EXTRA].filename)); this->extra_cfg = std::make_unique<GRFConfig>(this->files[GFT_EXTRA].filename);
/* We know the palette of the base set, so if the base NewGRF is not /* We know the palette of the base set, so if the base NewGRF is not
* setting one, use the palette of the base set and not the global * setting one, use the palette of the base set and not the global

View File

@ -521,7 +521,7 @@ void AddGRFTextToList(GRFTextList &list, uint8_t langid, uint32_t grfid, bool al
*/ */
void AddGRFTextToList(GRFTextWrapper &list, uint8_t langid, uint32_t grfid, bool allow_newlines, std::string_view text_to_add) void AddGRFTextToList(GRFTextWrapper &list, uint8_t langid, uint32_t grfid, bool allow_newlines, std::string_view text_to_add)
{ {
if (!list) list.reset(new GRFTextList()); if (list == nullptr) list = std::make_shared<GRFTextList>();
AddGRFTextToList(*list, langid, grfid, allow_newlines, text_to_add); AddGRFTextToList(*list, langid, grfid, allow_newlines, text_to_add);
} }
@ -533,7 +533,7 @@ void AddGRFTextToList(GRFTextWrapper &list, uint8_t langid, uint32_t grfid, bool
*/ */
void AddGRFTextToList(GRFTextWrapper &list, std::string_view text_to_add) void AddGRFTextToList(GRFTextWrapper &list, std::string_view text_to_add)
{ {
if (!list) list.reset(new GRFTextList()); if (list == nullptr) list = std::make_shared<GRFTextList>();
AddGRFTextToList(*list, GRFLX_UNSPECIFIED, text_to_add); AddGRFTextToList(*list, GRFLX_UNSPECIFIED, text_to_add);
} }

View File

@ -37,7 +37,7 @@ static void OpenBankFile(const std::string &filename)
/* If there is no sound file (nosound set), don't load anything */ /* If there is no sound file (nosound set), don't load anything */
if (filename.empty()) return; if (filename.empty()) return;
original_sound_file.reset(new RandomAccessFile(filename, BASESET_DIR)); original_sound_file = std::make_unique<RandomAccessFile>(filename, BASESET_DIR);
size_t pos = original_sound_file->GetPos(); size_t pos = original_sound_file->GetPos();
uint count = original_sound_file->ReadDword(); uint count = original_sound_file->ReadDword();