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

Merged
merged 1 commit into from
Jun 3, 2025

Conversation

HiPhish
Copy link
Contributor

@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.

@HiPhish HiPhish requested a review from a team as a code owner April 15, 2025 19:03
Copy link
Member

@joshuadavidthomas joshuadavidthomas left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice catch!

There is no need to check all conditions, we can short-circuit the
method as soon as any one condition is met.
@joshuadavidthomas joshuadavidthomas merged commit 0ebef8b into westerveltco:main Jun 3, 2025
21 checks passed
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.

2 participants