From f16399f4c9fbd69fe1a63bd9393887779491b8b0 Mon Sep 17 00:00:00 2001 From: Rubidium Date: Fri, 20 Oct 2023 20:18:31 +0200 Subject: [PATCH] Codechange: replace x.size() > 0 with !x.empty() --- src/3rdparty/squirrel/squirrel/sqbaselib.cpp | 2 +- src/3rdparty/squirrel/squirrel/sqfuncstate.cpp | 2 +- src/company_gui.cpp | 4 ++-- src/misc/dbg_helpers.cpp | 2 +- src/music/dmusic.cpp | 14 +++++++------- src/music/midifile.cpp | 2 +- src/network/network_content_gui.cpp | 2 +- src/newgrf.cpp | 2 +- src/newgrf_cargo.cpp | 2 +- src/os/macosx/string_osx.cpp | 2 +- src/os/windows/string_uniscribe.cpp | 4 ++-- src/story_gui.cpp | 2 +- src/vehicle_gui.cpp | 2 +- src/widgets/dropdown.cpp | 2 +- src/widgets/slider.cpp | 2 +- 15 files changed, 23 insertions(+), 23 deletions(-) diff --git a/src/3rdparty/squirrel/squirrel/sqbaselib.cpp b/src/3rdparty/squirrel/squirrel/sqbaselib.cpp index c79adadfe6..a875f4b882 100644 --- a/src/3rdparty/squirrel/squirrel/sqbaselib.cpp +++ b/src/3rdparty/squirrel/squirrel/sqbaselib.cpp @@ -763,7 +763,7 @@ static SQInteger closure_getinfos(HSQUIRRELVM v) { res->NewSlot(SQString::Create(_ss(v),"name",-1),nc->_name); res->NewSlot(SQString::Create(_ss(v),"paramscheck",-1),nc->_nparamscheck); SQObjectPtr typecheck; - if(nc->_typecheck.size() > 0) { + if(!nc->_typecheck.empty()) { typecheck = SQArray::Create(_ss(v), nc->_typecheck.size()); for(SQUnsignedInteger n = 0; n_typecheck.size(); n++) { diff --git a/src/3rdparty/squirrel/squirrel/sqfuncstate.cpp b/src/3rdparty/squirrel/squirrel/sqfuncstate.cpp index 0992658c84..1f9decc6e0 100644 --- a/src/3rdparty/squirrel/squirrel/sqfuncstate.cpp +++ b/src/3rdparty/squirrel/squirrel/sqfuncstate.cpp @@ -564,7 +564,7 @@ void SQFuncState::PopChildState() SQFuncState::~SQFuncState() { - while(_childstates.size() > 0) + while(!_childstates.empty()) { PopChildState(); } diff --git a/src/company_gui.cpp b/src/company_gui.cpp index fedd84374b..8a2d85cbf5 100644 --- a/src/company_gui.cpp +++ b/src/company_gui.cpp @@ -1008,7 +1008,7 @@ public: this->groups.ForceRebuild(); this->BuildGroupList((CompanyID)this->window_number); - if (this->groups.size() > 0) { + if (!this->groups.empty()) { this->sel = this->groups[0]->index; } } @@ -1095,7 +1095,7 @@ public: if (!Group::IsValidID(this->sel)) { this->sel = INVALID_GROUP; - if (this->groups.size() > 0) this->sel = this->groups[0]->index; + if (!this->groups.empty()) this->sel = this->groups[0]->index; } this->SetDirty(); diff --git a/src/misc/dbg_helpers.cpp b/src/misc/dbg_helpers.cpp index 7c4a15aa6a..8c18d7b77c 100644 --- a/src/misc/dbg_helpers.cpp +++ b/src/misc/dbg_helpers.cpp @@ -139,7 +139,7 @@ void DumpTarget::BeginStruct(size_t type_id, const std::string &name, const void { /* make composite name */ std::string cur_name = GetCurrentStructName(); - if (cur_name.size() > 0) { + if (!cur_name.empty()) { /* add name delimiter (we use structured names) */ cur_name += "."; } diff --git a/src/music/dmusic.cpp b/src/music/dmusic.cpp index 3aae02bc14..a528d8063b 100644 --- a/src/music/dmusic.cpp +++ b/src/music/dmusic.cpp @@ -939,14 +939,14 @@ static const char *LoadDefaultDLSFile(const char *user_dls) /* Calculate download size for the instrument. */ size_t i_size = sizeof(DMUS_DOWNLOADINFO) + sizeof(DMUS_INSTRUMENT); - if (dls_file.instruments[i].articulators.size() > 0) { + if (!dls_file.instruments[i].articulators.empty()) { /* Articulations are stored as two chunks, one containing meta data and one with the actual articulation data. */ offsets += 2; i_size += sizeof(DMUS_ARTICULATION2) + sizeof(CONNECTIONLIST) + sizeof(CONNECTION) * dls_file.instruments[i].articulators.size(); } for (std::vector::iterator rgn = dls_file.instruments[i].regions.begin(); rgn != dls_file.instruments[i].regions.end(); rgn++) { - if (rgn->articulators.size() > 0) { + if (!rgn->articulators.empty()) { offsets += 2; i_size += sizeof(DMUS_ARTICULATION2) + sizeof(CONNECTIONLIST) + sizeof(CONNECTION) * rgn->articulators.size(); } @@ -999,7 +999,7 @@ static const char *LoadDefaultDLSFile(const char *user_dls) instrument = inst_data + 1; /* Write global articulations. */ - if (dls_file.instruments[i].articulators.size() > 0) { + if (!dls_file.instruments[i].articulators.empty()) { inst_data->ulGlobalArtIdx = last_offset; offset_table[last_offset++] = (char *)instrument - inst_base; offset_table[last_offset++] = (char *)instrument + sizeof(DMUS_ARTICULATION2) - inst_base; @@ -1028,18 +1028,18 @@ static const char *LoadDefaultDLSFile(const char *user_dls) /* The wave sample data will be taken from the region, if defined, otherwise from the wave itself. */ if (rgn.wave_sample.cbSize != 0) { inst_region->WSMP = rgn.wave_sample; - if (rgn.wave_loops.size() > 0) MemCpyT(inst_region->WLOOP, &rgn.wave_loops.front(), rgn.wave_loops.size()); + if (!rgn.wave_loops.empty()) MemCpyT(inst_region->WLOOP, &rgn.wave_loops.front(), rgn.wave_loops.size()); instrument = (char *)(inst_region + 1) - sizeof(DMUS_REGION::WLOOP) + sizeof(WLOOP) * rgn.wave_loops.size(); } else { inst_region->WSMP = rgn.wave_sample; - if (dls_file.waves[wave_id].wave_loops.size() > 0) MemCpyT(inst_region->WLOOP, &dls_file.waves[wave_id].wave_loops.front(), dls_file.waves[wave_id].wave_loops.size()); + if (!dls_file.waves[wave_id].wave_loops.empty()) MemCpyT(inst_region->WLOOP, &dls_file.waves[wave_id].wave_loops.front(), dls_file.waves[wave_id].wave_loops.size()); instrument = (char *)(inst_region + 1) - sizeof(DMUS_REGION::WLOOP) + sizeof(WLOOP) * dls_file.waves[wave_id].wave_loops.size(); } /* Write local articulator data. */ - if (rgn.articulators.size() > 0) { + if (!rgn.articulators.empty()) { inst_region->ulRegionArtIdx = last_offset; offset_table[last_offset++] = (char *)instrument - inst_base; offset_table[last_offset++] = (char *)instrument + sizeof(DMUS_ARTICULATION2) - inst_base; @@ -1168,7 +1168,7 @@ void MusicDriver_DMusic::Stop() } /* Unloaded any instruments we loaded. */ - if (_dls_downloads.size() > 0) { + if (!_dls_downloads.empty()) { IDirectMusicPortDownload *download_port = nullptr; _port->QueryInterface(IID_IDirectMusicPortDownload, (LPVOID *)&download_port); diff --git a/src/music/midifile.cpp b/src/music/midifile.cpp index 6d218096c4..45a5bea24b 100644 --- a/src/music/midifile.cpp +++ b/src/music/midifile.cpp @@ -87,7 +87,7 @@ public: */ bool IsValid() const { - return this->buf.size() > 0; + return !this->buf.empty(); } /** diff --git a/src/network/network_content_gui.cpp b/src/network/network_content_gui.cpp index a408540914..672b2bca7e 100644 --- a/src/network/network_content_gui.cpp +++ b/src/network/network_content_gui.cpp @@ -824,7 +824,7 @@ public: case WID_NCL_NAME: if (this->content.SortType() == widget - WID_NCL_CHECKBOX) { this->content.ToggleSortOrder(); - if (this->content.size() > 0) this->list_pos = (int)this->content.size() - this->list_pos - 1; + if (!this->content.empty()) this->list_pos = (int)this->content.size() - this->list_pos - 1; } else { this->content.SetSortType(widget - WID_NCL_CHECKBOX); this->content.ForceResort(); diff --git a/src/newgrf.cpp b/src/newgrf.cpp index 67d2370a2d..5154ff9ead 100644 --- a/src/newgrf.cpp +++ b/src/newgrf.cpp @@ -5240,7 +5240,7 @@ static void NewSpriteGroup(ByteReader *buf) } group->default_group = GetGroupFromGroupID(setid, type, buf->ReadWord()); - group->error_group = ranges.size() > 0 ? ranges[0].group : group->default_group; + group->error_group = ranges.empty() ? group->default_group : ranges[0].group; /* nvar == 0 is a special case -- we turn our value into a callback result */ group->calculated_result = ranges.empty(); diff --git a/src/newgrf_cargo.cpp b/src/newgrf_cargo.cpp index 734c1ff025..75e9885130 100644 --- a/src/newgrf_cargo.cpp +++ b/src/newgrf_cargo.cpp @@ -86,7 +86,7 @@ CargoID GetCargoTranslation(uint8_t cargo, const GRFFile *grffile, bool usebit) /* Other cases use (possibly translated) cargobits */ - if (grffile->cargo_list.size() > 0) { + if (!grffile->cargo_list.empty()) { /* ...and the cargo is in bounds, then get the cargo ID for * the label */ if (cargo < grffile->cargo_list.size()) return GetCargoIDByLabel(grffile->cargo_list[cargo]); diff --git a/src/os/macosx/string_osx.cpp b/src/os/macosx/string_osx.cpp index d9ff5f2727..66e17e18f4 100644 --- a/src/os/macosx/string_osx.cpp +++ b/src/os/macosx/string_osx.cpp @@ -367,7 +367,7 @@ int MacOSStringCompare(std::string_view s1, std::string_view s2) /* Query CoreText for word and cluster break information. */ this->str_info.resize(utf16_to_utf8.size()); - if (utf16_str.size() > 0) { + if (!utf16_str.empty()) { CFAutoRelease str(CFStringCreateWithCharactersNoCopy(kCFAllocatorDefault, &utf16_str[0], utf16_str.size(), kCFAllocatorNull)); /* Get cluster breaks. */ diff --git a/src/os/windows/string_uniscribe.cpp b/src/os/windows/string_uniscribe.cpp index 9ee41f0eb7..dfb8ffd0c4 100644 --- a/src/os/windows/string_uniscribe.cpp +++ b/src/os/windows/string_uniscribe.cpp @@ -550,11 +550,11 @@ const int *UniscribeParagraphLayout::UniscribeVisualRun::GetGlyphToCharMap() con /* Query Uniscribe for word and cluster break information. */ this->str_info.resize(utf16_to_utf8.size()); - if (utf16_str.size() > 0) { + if (!utf16_str.empty()) { /* Itemize string into language runs. */ std::vector runs = UniscribeItemizeString(&utf16_str[0], (int32_t)utf16_str.size()); - for (std::vector::const_iterator run = runs.begin(); runs.size() > 0 && run != runs.end() - 1; run++) { + for (std::vector::const_iterator run = runs.begin(); !runs.empty() && run != runs.end() - 1; run++) { /* Get information on valid word and character break.s */ int len = (run + 1)->iCharPos - run->iCharPos; std::vector attr(len); diff --git a/src/story_gui.cpp b/src/story_gui.cpp index 0fece6a52b..c8eed0a98b 100644 --- a/src/story_gui.cpp +++ b/src/story_gui.cpp @@ -877,7 +877,7 @@ public: if (!_story_page_pool.IsValidID(this->selected_page_id)) { this->selected_page_id = INVALID_STORY_PAGE; } - if (this->selected_page_id == INVALID_STORY_PAGE && this->story_pages.size() > 0) { + if (this->selected_page_id == INVALID_STORY_PAGE && !this->story_pages.empty()) { /* No page is selected, but there exist at least one available. * => Select first page. */ diff --git a/src/vehicle_gui.cpp b/src/vehicle_gui.cpp index e3ade7780c..8b77f11c01 100644 --- a/src/vehicle_gui.cpp +++ b/src/vehicle_gui.cpp @@ -476,7 +476,7 @@ byte GetBestFittingSubType(Vehicle *v_from, Vehicle *v_for, CargoID dest_cargo_t byte ret_refit_cyc = 0; bool success = false; - if (subtypes.size() > 0) { + if (!subtypes.empty()) { /* Check whether any articulated part is refittable to 'dest_cargo_type' with a subtype listed in 'subtypes' */ for (Vehicle *v = v_for; v != nullptr; v = v->HasArticulatedPart() ? v->GetNextArticulatedPart() : nullptr) { const Engine *e = v->GetEngine(); diff --git a/src/widgets/dropdown.cpp b/src/widgets/dropdown.cpp index 09e31f9b26..665d8ebe07 100644 --- a/src/widgets/dropdown.cpp +++ b/src/widgets/dropdown.cpp @@ -134,7 +134,7 @@ struct DropdownWindow : Window { DropdownWindow(Window *parent, DropDownList &&list, int selected, int button, bool instant_close, const Point &position, const Dimension &size, Colours wi_colour, bool scroll) : Window(&_dropdown_desc), list(std::move(list)) { - assert(this->list.size() > 0); + assert(!this->list.empty()); this->position = position; diff --git a/src/widgets/slider.cpp b/src/widgets/slider.cpp index 59d0483668..f7678908d3 100644 --- a/src/widgets/slider.cpp +++ b/src/widgets/slider.cpp @@ -29,7 +29,7 @@ static const int SLIDER_WIDTH = 3; void DrawSliderWidget(Rect r, int min_value, int max_value, int value, const std::map &labels) { /* Allow space for labels. We assume they are in the small font. */ - if (labels.size() > 0) r.bottom -= FONT_HEIGHT_SMALL + WidgetDimensions::scaled.hsep_normal; + if (!labels.empty()) r.bottom -= FONT_HEIGHT_SMALL + WidgetDimensions::scaled.hsep_normal; max_value -= min_value;