Skip to content

Commit b964759

Browse files
Copilotmrm9084
andcommitted
Optimize _get_feature_flag to iterate backwards for better performance
Co-authored-by: mrm9084 <1054559+mrm9084@users.noreply.github.com>
1 parent b00f288 commit b964759

File tree

1 file changed

+3
-6
lines changed

1 file changed

+3
-6
lines changed

featuremanagement/_featuremanagerbase.py

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -41,13 +41,10 @@ def _get_feature_flag(configuration: Mapping[str, Any], feature_flag_name: str)
4141
if not feature_flags or not isinstance(feature_flags, list):
4242
return None
4343

44-
last_match = None
45-
for feature_flag in feature_flags:
44+
# Iterate backwards to find the last matching feature flag more efficiently
45+
for feature_flag in reversed(feature_flags):
4646
if feature_flag.get("id") == feature_flag_name:
47-
last_match = feature_flag
48-
49-
if last_match:
50-
return FeatureFlag.convert_from_json(last_match)
47+
return FeatureFlag.convert_from_json(feature_flag)
5148

5249
return None
5350

0 commit comments

Comments
 (0)