Skip to content

Commit b581c27

Browse files
committed
refactor: improve readability with container empty() and explicit strcmp
1 parent e6c28a4 commit b581c27

File tree

80 files changed

+314
-315
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

80 files changed

+314
-315
lines changed

Core/GameEngine/Source/Common/Audio/AudioEventRTS.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -329,7 +329,7 @@ void AudioEventRTS::generateFilename( void )
329329
adjustForLocalization(m_filenameToLoad);
330330
return;
331331
} else {
332-
if (m_eventInfo->m_sounds.size() == 0) {
332+
if (m_eventInfo->m_sounds.empty()) {
333333
m_filenameToLoad = AsciiString::TheEmptyString;
334334
return;
335335
}

Core/GameEngine/Source/Common/System/GameMemory.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2681,7 +2681,7 @@ MemoryPool *MemoryPoolFactory::findMemoryPool(const char *poolName)
26812681
{
26822682
for (MemoryPool *pool = m_firstPoolInFactory; pool; pool = pool->getNextPoolInList())
26832683
{
2684-
if (!strcmp(poolName, pool->getPoolName()))
2684+
if (strcmp(poolName, pool->getPoolName()) == 0)
26852685
{
26862686
DEBUG_ASSERTCRASH(poolName == pool->getPoolName(), ("hmm, ptrs should probably match here"));
26872687
return pool;

Core/GameEngine/Source/Common/System/Xfer.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -395,7 +395,7 @@ void Xfer::xferSTLObjectIDVector( std::vector<ObjectID> *objectIDVectorData )
395395
{
396396

397397
// sanity, the list should be empty before we transfer more data into it
398-
if( objectIDVectorData->size() != 0 )
398+
if( !objectIDVectorData->empty() )
399399
{
400400

401401
DEBUG_CRASH(( "Xfer::xferSTLObjectIDList - object vector should be empty before loading" ));
@@ -462,7 +462,7 @@ void Xfer::xferSTLObjectIDList( std::list< ObjectID > *objectIDListData )
462462
{
463463

464464
// sanity, the list should be empty before we transfer more data into it
465-
if( objectIDListData->size() != 0 )
465+
if( !objectIDListData->empty() )
466466
{
467467

468468
DEBUG_CRASH(( "Xfer::xferSTLObjectIDList - object list should be empty before loading" ));
@@ -528,7 +528,7 @@ void Xfer::xferSTLIntList( std::list< Int > *intListData )
528528
{
529529

530530
// sanity, the list should be empty before we transfer more data into it
531-
if( intListData->size() != 0 )
531+
if( !intListData->empty() )
532532
{
533533

534534
DEBUG_CRASH(( "Xfer::xferSTLIntList - int list should be empty before loading" ));

Core/GameEngine/Source/GameNetwork/GameSpy/LadderDefs.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,7 @@ static LadderInfo *parseLadder(AsciiString raw)
163163
// end of a ladder
164164
if (lad->playersPerTeam >= 1 && lad->playersPerTeam <= MAX_SLOTS/2)
165165
{
166-
if (lad->validFactions.size() == 0)
166+
if (lad->validFactions.empty())
167167
{
168168
DEBUG_LOG(("No factions specified. Using all."));
169169
lad->validFactions.clear();
@@ -190,7 +190,7 @@ static LadderInfo *parseLadder(AsciiString raw)
190190
}
191191
}
192192

193-
if (lad->validMaps.size() == 0)
193+
if (lad->validMaps.empty())
194194
{
195195
DEBUG_LOG(("No maps specified. Using all."));
196196
std::list<AsciiString> qmMaps = TheGameSpyConfig->getQMMaps();
@@ -503,7 +503,7 @@ void LadderList::checkLadder( AsciiString fname, Int index )
503503
return;
504504
}
505505

506-
if (li->validMaps.size() == 0)
506+
if (li->validMaps.empty())
507507
{
508508
DEBUG_LOG(("Bailing because of li->validMaps.size() == 0"));
509509
delete li;

Core/GameEngine/Source/GameNetwork/GameSpy/MainMenuUtils.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,7 @@ static void startOnline( void )
191191
noPatchBeforeOnlineCallback);
192192
return;
193193
}
194-
if (queuedDownloads.size())
194+
if (!queuedDownloads.empty())
195195
{
196196
if (!hasWriteAccess())
197197
{

Core/GameEngine/Source/GameNetwork/GameSpy/PeerDefs.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -340,7 +340,7 @@ void GameSpyInfo::addGroupRoom( GameSpyGroupRoom room )
340340
groupLabel.format("GUI:%s", room.m_name.str());
341341
room.m_translatedName = TheGameText->fetch(groupLabel);
342342
m_groupRooms[room.m_groupID] = room;
343-
if ( !stricmp("quickmatch", room.m_name.str()) )
343+
if ( stricmp("quickmatch", room.m_name.str()) == 0 )
344344
{
345345
DEBUG_LOG(("Group room %d (%s) is the QuickMatch room", room.m_groupID, room.m_name.str()));
346346
TheGameSpyConfig->setQMChannel(room.m_groupID);
@@ -378,7 +378,7 @@ void GameSpyInfo::joinBestGroupRoom( void )
378378
return;
379379
}
380380

381-
if (m_groupRooms.size())
381+
if (!m_groupRooms.empty())
382382
{
383383
int minID = -1;
384384
int minPlayers = 1000;

Core/GameEngine/Source/GameNetwork/GameSpy/Thread/PeerThread.cpp

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -471,7 +471,7 @@ Int PeerThreadClass::findServer( SBServer server )
471471
UnsignedInt oldPrivateIP = SBServerGetPrivateInetAddress(it->second);
472472
UnsignedShort oldPrivatePort = SBServerGetPrivateQueryPort(it->second);
473473
UnsignedInt oldPublicIP = SBServerGetPublicInetAddress(it->second);
474-
if (!strcmp(oldName, newName) &&
474+
if (strcmp(oldName, newName) == 0 &&
475475
oldPrivateIP == newPrivateIP &&
476476
oldPublicIP == newPublicIP &&
477477
oldPrivatePort == newPrivatePort)
@@ -1663,7 +1663,7 @@ void PeerThreadClass::Thread_Function()
16631663
m_playerFactions[i] = 0;
16641664
m_playerColors[i] = 0;
16651665
}
1666-
if (incomingRequest.password.length() > 0)
1666+
if (!incomingRequest.password.empty())
16671667
m_hasPassword = true;
16681668
else
16691669
m_hasPassword = false;
@@ -1714,7 +1714,7 @@ void PeerThreadClass::Thread_Function()
17141714

17151715
case PeerRequest::PEERREQUEST_UTMPLAYER:
17161716
{
1717-
if (incomingRequest.nick.length() > 0)
1717+
if (!incomingRequest.nick.empty())
17181718
{
17191719
peerUTMPlayer( peer, incomingRequest.nick.c_str(), incomingRequest.id.c_str(), incomingRequest.options.c_str(), PEERFalse );
17201720
}
@@ -1842,7 +1842,7 @@ void PeerThreadClass::handleQMMatch(PEER peer, Int mapIndex, Int seed,
18421842
Int i=0;
18431843
for (; i<MAX_SLOTS; ++i)
18441844
{
1845-
if (playerName[i] && stricmp(playerName[i], m_loginName.c_str()))
1845+
if (playerName[i] && stricmp(playerName[i], m_loginName.c_str()) != 0)
18461846
{
18471847
peerMessagePlayer( peer, playerName[i], "We're matched!", NormalMessage );
18481848
}
@@ -2705,7 +2705,7 @@ void playerLeftCallback(PEER peer, RoomType roomType, const char * nick, const c
27052705

27062706
if (t->getQMStatus() != QM_IDLE && t->getQMStatus() != QM_STOPPED)
27072707
{
2708-
if (!stricmp(t->getQMBotName().c_str(), nick))
2708+
if (stricmp(t->getQMBotName().c_str(), nick) == 0)
27092709
{
27102710
// matchbot left - bail
27112711
PeerResponse resp;
@@ -2845,9 +2845,9 @@ static void listingGamesCallback(PEER peer, PEERBool success, const char * name,
28452845
DEBUG_LOG(("Game name is '%s'", name));
28462846
const char *newname = SBServerGetStringValue(server, "gamename", (char *)name);
28472847
#if RTS_GENERALS
2848-
if (strcmp(newname, "ccgenerals"))
2848+
if (strcmp(newname, "ccgenerals") != 0)
28492849
#elif RTS_ZEROHOUR
2850-
if (strcmp(newname, "ccgenzh"))
2850+
if (strcmp(newname, "ccgenzh") != 0)
28512851
#endif
28522852
name = newname;
28532853
DEBUG_LOG(("Game name is now '%s'", name));

Core/GameEngine/Source/GameNetwork/GameSpy/Thread/PersistentStorageThread.cpp

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -102,12 +102,12 @@ static void debugDumpPlayerStats( const PSPlayerStats& stats )
102102
DEBUG_LOG(("gamesAsRandom: %d", stats.gamesAsRandom));
103103
}
104104

105-
if (stats.options.length())
105+
if (!stats.options.empty())
106106
{
107107
DEBUG_LOG(("Options: %s", stats.options.c_str()));
108108
}
109109

110-
if (stats.systemSpec.length())
110+
if (!stats.systemSpec.empty())
111111
{
112112
DEBUG_LOG(("systemSpec: %s", stats.systemSpec.c_str()));
113113
}
@@ -184,7 +184,7 @@ static void debugDumpPlayerStats( const PSPlayerStats& stats )
184184
DEBUG_LOG(("lastLadderPort: %d", stats.lastLadderPort));
185185
}
186186

187-
if (stats.lastLadderHost.length())
187+
if (!stats.lastLadderHost.empty())
188188
{
189189
DEBUG_LOG(("lastLadderHost: %s", stats.lastLadderHost.c_str()));
190190
}
@@ -246,12 +246,12 @@ void PSPlayerStats::incorporate( const PSPlayerStats& other )
246246
gamesAsRandom = other.gamesAsRandom;
247247
}
248248

249-
if (other.options.length())
249+
if (!other.options.empty())
250250
{
251251
options = other.options;
252252
}
253253

254-
if (other.systemSpec.length())
254+
if (!other.systemSpec.empty())
255255
{
256256
systemSpec = other.systemSpec;
257257
}
@@ -325,7 +325,7 @@ void PSPlayerStats::incorporate( const PSPlayerStats& other )
325325
{
326326
lastLadderPort = other.lastLadderPort;
327327
}
328-
if (other.lastLadderHost.length())
328+
if (!other.lastLadderHost.empty())
329329
{
330330
lastLadderHost = other.lastLadderHost;
331331
}
@@ -971,7 +971,7 @@ void PSThreadClass::Thread_Function()
971971
addedInDesyncs4 + req.addDesync, addedInDiscons4 + req.addDiscon));
972972
}
973973
pref.write();
974-
if (req.password.size() == 0)
974+
if (req.password.empty())
975975
return;
976976
}
977977
if (!req.player.id)
@@ -1370,13 +1370,13 @@ std::string GameSpyPSMessageQueueInterface::formatPlayerKVPairs( PSPlayerStats s
13701370
s.append(kvbuf);
13711371
}
13721372

1373-
if (stats.options.length())
1373+
if (!stats.options.empty())
13741374
{
13751375
snprintf(kvbuf, 256, "\\options\\%s", stats.options.c_str());
13761376
s.append(kvbuf);
13771377
}
13781378

1379-
if (stats.systemSpec.length())
1379+
if (!stats.systemSpec.empty())
13801380
{
13811381
snprintf(kvbuf, 256, "\\systemSpec\\%s", stats.systemSpec.c_str());
13821382
s.append(kvbuf);
@@ -1472,7 +1472,7 @@ std::string GameSpyPSMessageQueueInterface::formatPlayerKVPairs( PSPlayerStats s
14721472
sprintf(kvbuf, "\\ladderPort\\%d", stats.lastLadderPort);
14731473
s.append(kvbuf);
14741474
}
1475-
if (stats.lastLadderHost.length())
1475+
if (!stats.lastLadderHost.empty())
14761476
{
14771477
snprintf(kvbuf, 256, "\\ladderHost\\%s", stats.lastLadderHost.c_str());
14781478
s.append(kvbuf);

Core/GameEngine/Source/GameNetwork/NAT.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1169,7 +1169,7 @@ void NAT::processGlobalMessage(Int slotNum, const char *options) {
11691169
++ptr;
11701170
}
11711171
DEBUG_LOG(("NAT::processGlobalMessage - got message from slot %d, message is \"%s\"", slotNum, ptr));
1172-
if (!strncmp(ptr, "PROBED", strlen("PROBED"))) {
1172+
if (strncmp(ptr, "PROBED", strlen("PROBED")) == 0) {
11731173
// format: PROBED<node number>
11741174
// a probe has been sent at us, if we are waiting because of a netgear or something, we
11751175
// should start sending our own probes.
@@ -1180,7 +1180,7 @@ void NAT::processGlobalMessage(Int slotNum, const char *options) {
11801180
} else {
11811181
DEBUG_LOG(("NAT::processGlobalMessage - probed by node %d, not our target", node));
11821182
}
1183-
} else if (!strncmp(ptr, "CONNDONE", strlen("CONNDONE"))) {
1183+
} else if (strncmp(ptr, "CONNDONE", strlen("CONNDONE")) == 0) {
11841184
// format: CONNDONE<node number>
11851185
// we should get the node number of the player who's connection is done from the options
11861186
// and mark that down as part of the connectionStates.
@@ -1205,7 +1205,7 @@ void NAT::processGlobalMessage(Int slotNum, const char *options) {
12051205
} else {
12061206
DEBUG_LOG(("NAT::processGlobalMessage - got a connection done message that isn't from this round. node: %d sending node: %d", node, sendingNode));
12071207
}
1208-
} else if (!strncmp(ptr, "CONNFAILED", strlen("CONNFAILED"))) {
1208+
} else if (strncmp(ptr, "CONNFAILED", strlen("CONNFAILED")) == 0) {
12091209
// format: CONNFAILED<node number>
12101210
// we should get the node number of the player who's connection failed from the options
12111211
// and mark that down as part of the connectionStates.
@@ -1214,7 +1214,7 @@ void NAT::processGlobalMessage(Int slotNum, const char *options) {
12141214
DEBUG_LOG(("NAT::processGlobalMessage - node %d's connection failed, setting connection state to failed", node));
12151215
setConnectionState(node, NATCONNECTIONSTATE_FAILED);
12161216
}
1217-
} else if (!strncmp(ptr, "PORT", strlen("PORT"))) {
1217+
} else if (strncmp(ptr, "PORT", strlen("PORT")) == 0) {
12181218
// format: PORT<node number> <port number> <internal IP>
12191219
// we should get the node number and the mangled port number of the client we
12201220
// are supposed to be communicating with and start probing them. No, that was not

Core/GameEngineDevice/Source/StdDevice/Common/StdLocalFileSystem.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -241,7 +241,7 @@ void StdLocalFileSystem::getFileListInDirectory(const AsciiString& currentDirect
241241
while (!done) {
242242
std::string filenameStr = iter->path().filename().string();
243243
if (!iter->is_directory() && iter->path().extension() == searchExt &&
244-
(strcmp(filenameStr.c_str(), ".") && strcmp(filenameStr.c_str(), ".."))) {
244+
(strcmp(filenameStr.c_str(), ".") != 0 && strcmp(filenameStr.c_str(), ".."))) {
245245
// if we haven't already, add this filename to the list.
246246
// a stl set should only allow one copy of each filename
247247
AsciiString newFilename = iter->path().string().c_str();
@@ -268,7 +268,7 @@ void StdLocalFileSystem::getFileListInDirectory(const AsciiString& currentDirect
268268
while (!done) {
269269
std::string filenameStr = iter->path().filename().string();
270270
if(iter->is_directory() &&
271-
(strcmp(filenameStr.c_str(), ".") && strcmp(filenameStr.c_str(), ".."))) {
271+
(strcmp(filenameStr.c_str(), ".") != 0 && strcmp(filenameStr.c_str(), ".."))) {
272272
AsciiString tempsearchstr(filenameStr.c_str());
273273

274274
// recursively add files in subdirectories if required.
@@ -323,7 +323,7 @@ Bool StdLocalFileSystem::createDirectory(AsciiString directory)
323323
std::replace(fixedDirectory.begin(), fixedDirectory.end(), '\\', '/');
324324
#endif
325325

326-
if ((fixedDirectory.length() > 0) && (fixedDirectory.length() < _MAX_DIR)) {
326+
if ((!fixedDirectory.empty()) && (fixedDirectory.length() < _MAX_DIR)) {
327327
// Convert to host path
328328
std::filesystem::path path(std::move(fixedDirectory));
329329

0 commit comments

Comments
 (0)