From: Guus Sliepen Date: Wed, 7 Jul 2010 14:22:26 +0000 (+0200) Subject: Do not fill in comboString when we are not using it. X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=305ea9044896dfc390499790eed9ee318c4c4b58;p=quix0rs-blobwars.git Do not fill in comboString when we are not using it. According to callgrind, blobwars was spending 4% of its time in enemyBulletCollisions(), calling snprintf() to fill in comboString. However, this string was only used when an enemy was killed to check against objectives. So now snprintf() has been moved to where it actually is being used, dropping time spent in that function by 3.8%. --- diff --git a/src/enemies.cpp b/src/enemies.cpp index 1e59f83..9c998c3 100644 --- a/src/enemies.cpp +++ b/src/enemies.cpp @@ -377,8 +377,6 @@ void enemyBulletCollisions(Entity *bullet) if ((bullet->owner == &player) || (bullet->owner == &engine.world) || (bullet->flags & ENT_BOSS)) { - snprintf(comboString, sizeof comboString, "Combo-%s", bullet->name); - if (Collision::collision(enemy, bullet)) { if (bullet->id != WP_LASER) @@ -458,6 +456,7 @@ void enemyBulletCollisions(Entity *bullet) checkCombo(); } + snprintf(comboString, sizeof comboString, "Combo-%s", bullet->name); checkObjectives(comboString, false); checkObjectives("Enemy", false); checkObjectives(enemy->name, false); @@ -505,6 +504,7 @@ void enemyBulletCollisions(Entity *bullet) { if (player.currentWeapon != &weapon[WP_LASER]) { + snprintf(comboString, sizeof comboString, "Combo-%s", bullet->name); checkCombo(); checkObjectives(comboString, false); }