Replace uses of .size() or .length() with .empty() when appropriate (#25950)

This commit is contained in:
matheusvb3 authored and GitHub committed 2026-02-05 13:14:12 +01:00
1 parent d237721e68
commit 416a005b88
28 files changed
+60 -60

No files matched your search

+1 -1
View File
@@ -202,7 +202,7 @@ namespace OpenRCT2::Ui::FileBrowser
u8string RemovePatternWildcard(u8string_view pattern)
{
while (pattern.length() >= 1 && pattern.front() == '*')
while (!pattern.empty() && pattern.front() == '*')
{
pattern.remove_prefix(1);
}
+3 -3
View File
@@ -615,9 +615,9 @@ void CustomListView::Paint(WindowBase* w, RenderTarget& rt, const ScrollArea* sc
}
// Columns
if (Columns.size() == 0)
if (Columns.empty())
{
if (item.Cells.size() != 0)
if (!item.Cells.empty())
{
const auto& text = item.Cells[0];
if (!text.empty())
@@ -804,7 +804,7 @@ std::optional<RowColumn> CustomListView::GetItemIndexAt(const ScreenCoordsXY& po
}
// Check what column we pressed if there are any
if (result && Columns.size() > 0)
if (result && !Columns.empty())
{
bool found = false;
int32_t x = 0;
+3 -3
View File
@@ -897,7 +897,7 @@ namespace OpenRCT2::Ui::Windows
}
// Add window tabs
if (_info.Desc.Tabs.size() != 0)
if (!_info.Desc.Tabs.empty())
{
widgetList[WIDX_CONTENT_PANEL].top = kTabBarHeight;
}
@@ -919,7 +919,7 @@ namespace OpenRCT2::Ui::Windows
// Add custom widgets
auto totalWidgets = _info.Desc.Widgets.size();
auto tabWidgetsOffset = totalWidgets;
if (_info.Desc.Tabs.size() != 0)
if (!_info.Desc.Tabs.empty())
{
totalWidgets += _info.Desc.Tabs[page].Widgets.size();
}
@@ -1271,7 +1271,7 @@ namespace OpenRCT2::Ui::Windows
auto& widget = w->widgets[widgetIndex];
auto lastSelectedIndex = customWidgetInfo->SelectedIndex;
if (customWidgetInfo->Items.size() == 0)
if (customWidgetInfo->Items.empty())
{
selectedIndex = -1;
}
+12 -12
View File
@@ -1274,7 +1274,7 @@ namespace OpenRCT2::Ui::Windows
}
FootpathUpdateProvisional();
if (_provisionalFootpath.tiles.size() == 0)
if (_provisionalFootpath.tiles.empty())
return;
// Try and place path
@@ -1946,7 +1946,7 @@ namespace OpenRCT2::Ui::Windows
FootpathRemoveProvisional();
GameActions::Result res;
std::vector<ProvisionalTile> succesfulTiles{};
std::vector<ProvisionalTile> successfulTiles{};
money64 cost = 0;
for (const auto& tile : tiles)
{
@@ -1958,20 +1958,20 @@ namespace OpenRCT2::Ui::Windows
// from glitching through the existing path.
if (res.error == GameActions::Status::ok || res.error == GameActions::Status::itemAlreadyPlaced)
{
succesfulTiles.emplace_back(tile);
successfulTiles.emplace_back(tile);
cost += res.cost;
}
}
bool anySuccesful = succesfulTiles.size() > 0;
if (anySuccesful)
bool anySuccessful = (!successfulTiles.empty());
if (anySuccessful)
{
_provisionalFootpath.surfaceIndex = type;
_provisionalFootpath.railingsIndex = railingsType;
_provisionalFootpath.positionA = footpathLocA;
_provisionalFootpath.positionB = footpathLocB;
_provisionalFootpath.startZ = startZ;
_provisionalFootpath.tiles = succesfulTiles;
_provisionalFootpath.tiles = successfulTiles;
_provisionalFootpath.constructFlags = constructFlags;
_provisionalFootpath.flags.set(ProvisionalPathFlag::placed);
@@ -1987,26 +1987,26 @@ namespace OpenRCT2::Ui::Windows
if (!isToolActive(WindowClass::scenery))
{
if (succesfulTiles.size() == 0)
if (successfulTiles.empty())
{
// If we can't build this, don't show a virtual floor.
VirtualFloorSetHeight(0);
}
else if (
succesfulTiles[0].slope.type == FootpathSlopeType::flat
|| succesfulTiles[0].position.z < _footpathConstructFromPosition.z)
successfulTiles[0].slope.type == FootpathSlopeType::flat
|| successfulTiles[0].position.z < _footpathConstructFromPosition.z)
{
// Going either straight on, or down.
VirtualFloorSetHeight(succesfulTiles[0].position.z);
VirtualFloorSetHeight(successfulTiles[0].position.z);
}
else
{
// Going up in the world!
VirtualFloorSetHeight(succesfulTiles[0].position.z + kLandHeightStep);
VirtualFloorSetHeight(successfulTiles[0].position.z + kLandHeightStep);
}
}
return anySuccesful ? cost : kMoney64Undefined;
return anySuccessful ? cost : kMoney64Undefined;
}
/**
+1 -1
View File
@@ -2846,7 +2846,7 @@ namespace OpenRCT2::Ui::Windows
auto& objManager = GetContext()->GetObjectManager();
auto& rideEntries = objManager.GetAllRideEntries(rideType);
// If there are no vehicles for this ride type, enable all the track pieces.
if (rideEntries.size() == 0)
if (rideEntries.empty())
{
disabledGroups.reset();
}
+1 -1
View File
@@ -552,7 +552,7 @@ namespace OpenRCT2::Ui::Windows
const auto& rideManager = RideManager(gameState);
auto allClosed = true;
auto allOpen = false;
if (_rideList.size() > 0 && std::size(rideManager) != 0)
if (!_rideList.empty() && std::size(rideManager) != 0)
{
auto c = static_cast<RideClassification>(page);
allClosed = std::none_of(rideManager.begin(), rideManager.end(), [c](const Ride& rideRef) {
+3 -3
View File
@@ -825,7 +825,7 @@ namespace OpenRCT2::Ui::Windows
}
auto windowWidth = width;
if (_tabEntries.size() > 0)
if (!_tabEntries.empty())
{
const auto lastTabIndex = GetMaxTabCountInARow() == kMaxTabsPerRow ? kMaxTabsPerRow - 1
: _tabEntries.size() - 1;
@@ -916,7 +916,7 @@ namespace OpenRCT2::Ui::Windows
auto sceneryObjectType = GetObjectTypeFromSceneryType(selectedSceneryEntry.SceneryType);
auto& objManager = GetContext()->GetObjectManager();
auto sceneryObject = objManager.GetLoadedObject(sceneryObjectType, selectedSceneryEntry.EntryIndex);
if (sceneryObject != nullptr && sceneryObject->GetAuthors().size() > 0)
if (sceneryObject != nullptr && !sceneryObject->GetAuthors().empty())
{
std::string authorsString;
const auto& authors = sceneryObject->GetAuthors();
@@ -1007,7 +1007,7 @@ namespace OpenRCT2::Ui::Windows
tabInfo.AddEntryToBack(sceneryEntry);
}
}
if (tabInfo.Entries.size() > 0)
if (!tabInfo.Entries.empty())
{
_tabEntries.push_back(std::move(tabInfo));
}
+1 -1
View File
@@ -231,7 +231,7 @@ namespace OpenRCT2::Ui::Windows
_reloadTrackDesigns = false;
// Start with first track highlighted
selectedListItem = 0;
if (_trackDesigns.size() != 0 && gLegacyScene != LegacyScene::trackDesignsManager)
if (!_trackDesigns.empty() && gLegacyScene != LegacyScene::trackDesignsManager)
{
selectedListItem = 1;
}
+3 -3
View File
@@ -153,7 +153,7 @@ namespace OpenRCT2
if (i == csl.size() || csl[i] == ',')
{
auto el = csl.substr(elStart, i - elStart);
if (el.size() != 0)
if (!el.empty())
func(el);
elStart = i + 1;
}
@@ -204,9 +204,9 @@ namespace OpenRCT2
enabledList.push_back(',');
}
}
if (orderList.size() > 0)
if (!orderList.empty())
orderList.pop_back();
if (enabledList.size() > 0)
if (!enabledList.empty())
enabledList.pop_back();
Config::Get().general.assetPackOrder = orderList;
Config::Get().general.enabledAssetPacks = enabledList;
+1 -1
View File
@@ -668,7 +668,7 @@ struct GameStateSnapshots final : public IGameStateSnapshots
else
{
CompareSpriteData(spriteBase, spriteCmp, changeData);
if (changeData.diffs.size() == 0)
if (changeData.diffs.empty())
{
changeData.changeType = GameStateSpriteChange::EQUAL;
}
@@ -124,7 +124,7 @@ namespace OpenRCT2
Console::WriteLine("ObjectType: %s, Number of Objects: %d", typeToName[EnumValue(objType)], list.size());
for (auto& obj : list)
{
if (obj.Generation == ObjectGeneration::JSON && obj.Identifier.size() == 0)
if (obj.Generation == ObjectGeneration::JSON && obj.Identifier.empty())
{
// Empty object slot don't output anything
continue;
+1 -1
View File
@@ -178,7 +178,7 @@ struct DataSerializerTraitsT<std::string>
static void log(OpenRCT2::IStream* stream, const std::string& str)
{
stream->Write("\"", 1);
if (str.size() != 0)
if (!str.empty())
{
stream->Write(str.data(), str.size());
}
+1 -1
View File
@@ -90,7 +90,7 @@ namespace OpenRCT2::Http
{
// Ignore first header as that is the HTTP version which
// we don't really count as a header.
if (index != 0 && wKey.size() != 0)
if (index != 0 && !wKey.empty())
{
auto key = String::toUtf8(wKey);
auto value = String::toUtf8(wValue);
+1 -1
View File
@@ -185,7 +185,7 @@ namespace OpenRCT2::String
*/
constexpr std::optional<int> utf8GetCodePointSize(std::string_view v)
{
if (v.size() >= 1 && !(v[0] & 0x80))
if (!v.empty() && !(v[0] & 0x80))
{
return { 1 };
}
+1 -1
View File
@@ -296,7 +296,7 @@ namespace OpenRCT2
EntityBase* EntityRegistry::CreateEntity(EntityType type)
{
if (_freeIdList.size() == 0)
if (_freeIdList.empty())
{
// No free sprites.
return nullptr;
@@ -1273,7 +1273,7 @@ static void ConsoleCommandForceDate([[maybe_unused]] InteractiveConsole& console
int32_t year = 0;
int32_t month = 0;
int32_t day = 0;
if (argv.size() < 1 || argv.size() > 3)
if (argv.empty() || argv.size() > 3)
{
return;
}
@@ -1327,7 +1327,7 @@ static void ConsoleCommandForceDate([[maybe_unused]] InteractiveConsole& console
static void ConsoleCommandLoadPark([[maybe_unused]] InteractiveConsole& console, [[maybe_unused]] const arguments_t& argv)
{
if (argv.size() < 1)
if (argv.empty())
{
console.WriteLine("Parameters required <filename>");
return;
@@ -1362,7 +1362,7 @@ static void ConsoleCommandLoadPark([[maybe_unused]] InteractiveConsole& console,
static void ConsoleCommandSavePark([[maybe_unused]] InteractiveConsole& console, [[maybe_unused]] const arguments_t& argv)
{
if (argv.size() < 1)
if (argv.empty())
{
SaveGameCmd();
}
@@ -1398,7 +1398,7 @@ static void ConsoleCommandReplayStartRecord(InteractiveConsole& console, const a
return;
}
if (argv.size() < 1)
if (argv.empty())
{
console.WriteFormatLine("Parameters required <replay_name> [<max_ticks = 0xFFFFFFFF>]");
return;
@@ -1471,7 +1471,7 @@ static void ConsoleCommandReplayStart(InteractiveConsole& console, const argumen
return;
}
if (argv.size() < 1)
if (argv.empty())
{
console.WriteFormatLine("Parameters required <replay_name>");
return;
@@ -1556,7 +1556,7 @@ static void ConsoleCommandReplayNormalise(InteractiveConsole& console, const arg
static void ConsoleCommandMpDesync(InteractiveConsole& console, const arguments_t& argv)
{
int32_t desyncType = 0;
if (argv.size() >= 1)
if (!argv.empty())
{
desyncType = atoi(argv[0].c_str());
}
@@ -1698,7 +1698,7 @@ static void ConsoleCommandProfilerStart([[maybe_unused]] InteractiveConsole& con
static void ConsoleCommandProfilerExportCSV(
[[maybe_unused]] InteractiveConsole& console, [[maybe_unused]] const arguments_t& argv)
{
if (argv.size() < 1)
if (argv.empty())
{
console.WriteLineError("Missing argument: <file path>");
}
@@ -1719,7 +1719,7 @@ static void ConsoleCommandProfilerStop([[maybe_unused]] InteractiveConsole& cons
Profiling::Disable();
// Export to CSV if argument is provided.
if (argv.size() >= 1)
if (!argv.empty())
{
return ConsoleCommandProfilerExportCSV(console, argv);
}
+2 -2
View File
@@ -790,7 +790,7 @@ namespace OpenRCT2::Network
}
}
if (colours.size() == 0 || (colours.size() == 1 && colours[0] == "{WHITE}"))
if (colours.empty() || (colours.size() == 1 && colours[0] == "{WHITE}"))
{
formatted += "{BABYBLUE}";
formatted += fromPlayer->Name;
@@ -1677,7 +1677,7 @@ namespace OpenRCT2::Network
{
json_t jsonObj = {
{ "name", Config::Get().network.serverName },
{ "requiresPassword", _password.size() > 0 },
{ "requiresPassword", !_password.empty() },
{ "version", GetVersion() },
{ "players", GetNumVisiblePlayers() },
{ "maxPlayers", Config::Get().network.maxplayers },
+1 -1
View File
@@ -244,7 +244,7 @@ namespace OpenRCT2
}
}
if (range.size() > 0)
if (!range.empty())
{
size_t placeHoldersAdded = 0;
for (auto i : range)
+1 -1
View File
@@ -194,7 +194,7 @@ namespace OpenRCT2
bool MusicObject::SupportsRideType(ride_type_t rideType, bool onlyAllowIfExplicitlyListed)
{
if (_rideTypes.size() == 0)
if (_rideTypes.empty())
{
// Some rides, like the merry-go-round, need music objects to explicitly list them.
return !onlyAllowIfExplicitlyListed;
+2 -2
View File
@@ -194,7 +194,7 @@ namespace OpenRCT2
ObjectSourceGame Object::GetFirstSourceGame() const
{
if (_sourceGames.size() == 0)
if (_sourceGames.empty())
return ObjectSourceGame::custom;
return _sourceGames[0];
@@ -423,7 +423,7 @@ namespace OpenRCT2
{
LOG_WARNING("%i fields found in version string '%s', expected X.Y.Z", nums.size(), version);
}
if (nums.size() == 0)
if (nums.empty())
{
LOG_WARNING("No fields found in version string '%s', expected X.Y.Z", version);
return std::make_tuple(0, 0, 0);
+2 -2
View File
@@ -966,7 +966,7 @@ namespace OpenRCT2
for (size_t index = 0; index < jCarColours.size(); index++)
{
auto config = ReadJsonColourConfiguration(jCarColours[index]);
if (config.size() >= 1)
if (!config.empty())
{
list.list[index] = config[0];
list.count++;
@@ -990,7 +990,7 @@ namespace OpenRCT2
VehicleColour carColour = {};
auto colours = Json::AsArray(jColours);
if (colours.size() >= 1)
if (!colours.empty())
{
carColour.Body = Drawing::colourFromString(Json::GetString(colours[0]));
carColour.Trim = carColour.Body;
+2 -2
View File
@@ -775,7 +775,7 @@ namespace OpenRCT2
static constexpr uint8_t DESCRIPTOR_DAT = 0;
static constexpr uint8_t DESCRIPTOR_PARKOBJ = 1;
if (os.getMode() == OrcaStream::Mode::writing && ExportObjectsList.size() == 0)
if (os.getMode() == OrcaStream::Mode::writing && ExportObjectsList.empty())
{
// Do not emit chunk if there are no packed objects
return;
@@ -2188,7 +2188,7 @@ namespace OpenRCT2
{
value = std::get<1>(*fr);
}
else if (table.size() > 0)
else if (!table.empty())
{
value = std::get<1>(table[0]);
}
+1 -1
View File
@@ -1618,7 +1618,7 @@ namespace OpenRCT2::RCT1
}
// Set last element flag in case the original last element was never added
if (tileElements.size() > 0)
if (!tileElements.empty())
{
tileElements.back().SetLastForTile(true);
}
+1 -1
View File
@@ -1292,7 +1292,7 @@ namespace OpenRCT2::RCT2
}
// Set last element flag in case the original last element was never added
if (tileElements.size() > 0)
if (!tileElements.empty())
{
tileElements.back().SetLastForTile(true);
}
+3 -3
View File
@@ -2246,7 +2246,7 @@ int32_t RideGetUnusedPresetVehicleColour(ObjectEntryIndex subType)
}
// If all presets have been used, just go with a random preset
if (unused.size() == 0)
if (unused.empty())
return UtilRand() % colourPresets->count;
// Choose a random preset from the list of unused presets
@@ -4326,7 +4326,7 @@ int32_t RideGetRandomColourPresetIndex(ride_type_t rideType)
}
// If all presets have been used, just go with a random preset
if (unused.size() == 0)
if (unused.empty())
return UtilRand() % colourPresets.count;
// Choose a random preset from the list of unused presets
@@ -5557,7 +5557,7 @@ ObjectEntryIndex RideGetEntryIndex(ride_type_t rideType, ObjectEntryIndex rideSu
{
auto& objManager = GetContext()->GetObjectManager();
auto& rideEntries = objManager.GetAllRideEntries(rideType);
if (rideEntries.size() > 0)
if (!rideEntries.empty())
{
subType = rideEntries[0];
for (auto rideEntryIndex : rideEntries)
+1 -1
View File
@@ -959,7 +959,7 @@ void ScriptEngine::CheckAndStartPlugins()
void ScriptEngine::ProcessREPL()
{
while (_evalQueue.size() > 0)
while (!_evalQueue.empty())
{
auto item = std::move(_evalQueue.front());
_evalQueue.pop();
+1 -1
View File
@@ -471,7 +471,7 @@ void DeleteBanner(BannerIndex id)
void TrimBanners()
{
auto& gameState = getGameState();
if (gameState.banners.size() > 0)
if (!gameState.banners.empty())
{
auto lastBannerId = gameState.banners.size() - 1;
while (lastBannerId != std::numeric_limits<size_t>::max() && gameState.banners[lastBannerId].isNull())
+1 -1
View File
@@ -1097,7 +1097,7 @@ static int32_t FootpathIsConnectedToMapEdgeHelper(CoordsXYZ footpathPos, int32_t
// Loads the next tile to visit into our variables
auto LoadNextTileElement = [&tiles, &numPendingTiles](TileState& t_currentTile) -> void {
// Do not continue if there are no tiles in the list
if (tiles.size() == 0)
if (tiles.empty())
return;
// Find the next unprocessed tile