From 7bb751dda843891141c966b7396827ac5b27d9e5 Mon Sep 17 00:00:00 2001 From: Night-Sky-To <123367693+Night-Sky-To@users.noreply.github.com> Date: Mon, 12 Jun 2023 13:18:11 +0800 Subject: [PATCH] Update character_modifier.cpp Co-authored-by: SurFlurer --- src/character_modifier.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/character_modifier.cpp b/src/character_modifier.cpp index 3a643c435495e..06b84b4c33c64 100644 --- a/src/character_modifier.cpp +++ b/src/character_modifier.cpp @@ -223,6 +223,8 @@ float Character::get_limb_score( const limb_score_id &score, const body_part_typ skill = get_skill_level( skill_swimming ); } float total = 0.0f; + // Avoid call has_flag() in a loop to improve performance + bool cache_flag_EFFECT_LIMB_SCORE_MOD_LOCAL = has_flag( flag_EFFECT_LIMB_SCORE_MOD_LOCAL ); for( const std::pair &id : body ) { float mod = 0.0f; if( bp == body_part_type::type::num_types ) { @@ -231,7 +233,7 @@ float Character::get_limb_score( const limb_score_id &score, const body_part_typ mod = id.second.get_limb_score( score, skill, override_encumb, override_wounds ) * id.first->limbtypes.at( bp ); } - if( has_flag( flag_EFFECT_LIMB_SCORE_MOD_LOCAL ) ) { + if( cache_flag_EFFECT_LIMB_SCORE_MOD_LOCAL ) { for( const effect &local : get_effects_from_bp( id.first ) ) { float local_mul = 1.0f; // Second filter to only apply the local effects at this step (non-local modifiers are already calulated)