Skip to content

Short-circuit in NavGroup.get_active #173

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

HiPhish
Copy link

@HiPhish HiPhish commented Apr 15, 2025

While doing #172 I also noticed potential for a small performance improvement.

  • If the superclass check succeeds we do not need to check the items because the or in the return statement would short-circuit anyway regardless whether any of the items are active or not
  • Since any returns True on the first success we do not need the entire list. Using a generator saves us from evaluating the remaining get_active calls. If any of the items has an expensive implementation of get_active we save ourselves from calling it.

There is no need to check all conditions, we can short-circuit the
method as soon as any one condition is met.
@HiPhish HiPhish requested a review from a team as a code owner April 15, 2025 19:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant