Skip to content

Commit af4f950

Browse files
authored
perf: Remove superfluous null tests in iterateObjects callbacks (TheSuperHackers#2658)
1 parent a42cd64 commit af4f950

13 files changed

Lines changed: 27 additions & 73 deletions

File tree

Generals/Code/GameEngine/Source/Common/RTS/Player.cpp

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1154,9 +1154,6 @@ struct PlayerObjectFindInfo
11541154
//-------------------------------------------------------------------------------------------------
11551155
static void doFindCommandCenter(Object* obj, void* userData)
11561156
{
1157-
if (!obj)
1158-
return;
1159-
11601157
PlayerObjectFindInfo* info = (PlayerObjectFindInfo*)userData;
11611158

11621159
if (info->obj == nullptr

Generals/Code/GameEngine/Source/GameClient/GUI/ControlBar/ControlBarCommandProcessing.cpp

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -71,10 +71,6 @@ struct SelectObjectsInfo
7171
static void selectObjectOfType( Object* obj, void* selectObjectsInfo )
7272
{
7373
SelectObjectsInfo *soInfo = (SelectObjectsInfo*)selectObjectsInfo;
74-
if( !obj || !soInfo )
75-
{
76-
return;
77-
}
7874

7975
//Do the templates match?
8076
if( obj->getTemplate()->isEquivalentTo( soInfo->thingTemplate ) )

Generals/Code/GameEngine/Source/GameClient/MessageStream/CommandXlat.cpp

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -98,8 +98,6 @@
9898
void countObjects(Object *obj, void *userData)
9999
{
100100
Int *numObjects = (Int *)userData;
101-
if (!numObjects || !obj)
102-
return;
103101

104102
DEBUG_LOG(("Looking at obj %d (%s) - isEffectivelyDead()==%d, isDestroyed==%d, numObjects==%d",
105103
obj->getID(), obj->getTemplate()->getName().str(), obj->isEffectivelyDead(), obj->isDestroyed(), *numObjects));
@@ -110,9 +108,6 @@ void countObjects(Object *obj, void *userData)
110108

111109
void printObjects(Object *obj, void *userData)
112110
{
113-
if (!obj)
114-
return;
115-
116111
Bool isDead = obj->isEffectivelyDead() || obj->isDestroyed();
117112
Bool isInert = obj->isKindOf(KINDOF_INERT);
118113
AsciiString statusStr = (isDead)?"Dead":(isInert)?"Inert":"Living";
@@ -858,10 +853,6 @@ struct CommandCenterLocator
858853

859854
void findCommandCenterOrMostExpensiveBuilding(Object* obj, void* vccl)
860855
{
861-
if (!obj) {
862-
return;
863-
}
864-
865856
CommandCenterLocator *ccl = (CommandCenterLocator*) vccl;
866857

867858
// here's the deal. We want to get the first Command Center in the list.
@@ -911,9 +902,7 @@ struct HeroHolder
911902

912903
void amIAHero(Object* obj, void* heroHolder)
913904
{
914-
915-
916-
if (!obj || ((HeroHolder*)heroHolder)->hero != nullptr)
905+
if (((HeroHolder*)heroHolder)->hero != nullptr)
917906
{
918907
return;
919908
}

Generals/Code/GameEngine/Source/GameLogic/AI/AIDock.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -648,7 +648,7 @@ void findDrone( Object *obj, void *droneInfo )
648648
{
649649
DroneInfo *dInfo = (DroneInfo*)droneInfo;
650650

651-
if( !dInfo->found && obj )
651+
if( !dInfo->found )
652652
{
653653
if( obj->isKindOf( KINDOF_DRONE ) && obj->getProducerID() == dInfo->owner->getID() )
654654
{

Generals/Code/GameEngine/Source/GameLogic/ScriptEngine/ScriptActions.cpp

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -92,20 +92,17 @@ extern void oversizeTheTerrain(Int amount);
9292
// or the indicator color. this allows us to force the situation. (srj)
9393
static void updateTeamAndPlayerStuff( Object *obj, void *userData )
9494
{
95-
if (obj)
96-
{
97-
obj->updateUpgradeModules();
95+
obj->updateUpgradeModules();
9896

99-
// srj sez: apparently we have to do this too, since Team::setControllingPlayer
100-
// does not. Might make more sense to do it there, but am scared to at this point.
101-
Drawable* draw = obj->getDrawable();
102-
if (draw)
103-
{
104-
if (TheGlobalData->m_timeOfDay == TIME_OF_DAY_NIGHT)
105-
draw->setIndicatorColor(obj->getNightIndicatorColor());
106-
else
107-
draw->setIndicatorColor(obj->getIndicatorColor());
108-
}
97+
// srj sez: apparently we have to do this too, since Team::setControllingPlayer
98+
// does not. Might make more sense to do it there, but am scared to at this point.
99+
Drawable* draw = obj->getDrawable();
100+
if (draw)
101+
{
102+
if (TheGlobalData->m_timeOfDay == TIME_OF_DAY_NIGHT)
103+
draw->setIndicatorColor(obj->getNightIndicatorColor());
104+
else
105+
draw->setIndicatorColor(obj->getIndicatorColor());
109106
}
110107
}
111108
//-------------------------------------------------------------------------------------------------

Generals/Code/GameEngine/Source/GameLogic/System/GameLogic.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2137,7 +2137,7 @@ void GameLogic::tryStartNewGame( Bool loadingSaveGame )
21372137
//-----------------------------------------------------------------------------------------
21382138
static void findAndSelectCommandCenter(Object *obj, void* alreadyFound)
21392139
{
2140-
if (!((*(Bool*)alreadyFound)) && obj && obj->isKindOf(KINDOF_COMMANDCENTER) )
2140+
if (!((*(Bool*)alreadyFound)) && obj->isKindOf(KINDOF_COMMANDCENTER) )
21412141
{
21422142
((*(Bool*)alreadyFound)) = TRUE;
21432143
TheGameLogic->selectObject(obj, TRUE, obj->getControllingPlayer()->getPlayerMask(), obj->isLocallyControlled());

GeneralsMD/Code/GameEngine/Source/Common/RTS/AcademyStats.cpp

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ void findDozerCommandSet( Object *object, void *userData )
8888
{
8989
return;
9090
}
91-
if( object && object->isKindOf( KINDOF_DOZER ) )
91+
if( object->isKindOf( KINDOF_DOZER ) )
9292
{
9393
dozerCommandSet = TheControlBar->findCommandSet( object->getCommandSetString() );
9494
}
@@ -284,10 +284,6 @@ void AcademyStats::init( const Player *player )
284284
static void updateAcademyStats( Object *obj, void *userData )
285285
{
286286
AcademyStats *academy = (AcademyStats*)userData;
287-
if( !obj || !academy )
288-
{
289-
return;
290-
}
291287

292288
if( academy->isFirstUpdate() )
293289
{

GeneralsMD/Code/GameEngine/Source/Common/RTS/Player.cpp

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1204,9 +1204,6 @@ struct PlayerObjectFindInfo
12041204
//-------------------------------------------------------------------------------------------------
12051205
static void doFindCommandCenter(Object* obj, void* userData)
12061206
{
1207-
if (!obj)
1208-
return;
1209-
12101207
PlayerObjectFindInfo* info = (PlayerObjectFindInfo*)userData;
12111208

12121209
if (info->obj == nullptr

GeneralsMD/Code/GameEngine/Source/GameClient/GUI/ControlBar/ControlBarCommandProcessing.cpp

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -71,10 +71,6 @@ struct SelectObjectsInfo
7171
static void selectObjectOfType( Object* obj, void* selectObjectsInfo )
7272
{
7373
SelectObjectsInfo *soInfo = (SelectObjectsInfo*)selectObjectsInfo;
74-
if( !obj || !soInfo )
75-
{
76-
return;
77-
}
7874

7975
//Do the templates match?
8076
if( obj->getTemplate()->isEquivalentTo( soInfo->thingTemplate ) )

GeneralsMD/Code/GameEngine/Source/GameClient/MessageStream/CommandXlat.cpp

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -97,8 +97,6 @@
9797
void countObjects(Object *obj, void *userData)
9898
{
9999
Int *numObjects = (Int *)userData;
100-
if (!numObjects || !obj)
101-
return;
102100

103101
DEBUG_LOG(("Looking at obj %d (%s) - isEffectivelyDead()==%d, isDestroyed==%d, numObjects==%d",
104102
obj->getID(), obj->getTemplate()->getName().str(), obj->isEffectivelyDead(), obj->isDestroyed(), *numObjects));
@@ -109,9 +107,6 @@ void countObjects(Object *obj, void *userData)
109107

110108
void printObjects(Object *obj, void *userData)
111109
{
112-
if (!obj)
113-
return;
114-
115110
Bool isDead = obj->isEffectivelyDead() || obj->isDestroyed();
116111
Bool isInert = obj->isKindOf(KINDOF_INERT);
117112
AsciiString statusStr = (isDead)?"Dead":(isInert)?"Inert":"Living";
@@ -912,10 +907,6 @@ struct CommandCenterLocator
912907

913908
void findCommandCenterOrMostExpensiveBuilding(Object* obj, void* vccl)
914909
{
915-
if (!obj) {
916-
return;
917-
}
918-
919910
CommandCenterLocator *ccl = (CommandCenterLocator*) vccl;
920911

921912
// here's the deal. We want to get the first Command Center in the list.
@@ -965,9 +956,7 @@ struct HeroHolder
965956

966957
void amIAHero(Object* obj, void* heroHolder)
967958
{
968-
969-
970-
if (!obj || ((HeroHolder*)heroHolder)->hero != nullptr)
959+
if (((HeroHolder*)heroHolder)->hero != nullptr)
971960
{
972961
return;
973962
}

0 commit comments

Comments
 (0)