-
Notifications
You must be signed in to change notification settings - Fork 3
β‘ Bolt: Fast Lookups by Replacing next() with for loops
#352
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -129,7 +129,10 @@ def from_extension(cls, ext: str) -> ConfigLanguage | None: | |
| """ | ||
| ext = ext.lower() if ext.startswith(".") else ext | ||
| if ext in cls.all_extensions(): | ||
| return next((language for language in cls if ext in language.extensions), None) | ||
| # Optimization: Loop with early return is significantly faster than next() generator comprehension | ||
| for language in cls: | ||
| if ext in language.extensions: | ||
| return language | ||
| return None | ||
|
|
||
| @property | ||
|
|
@@ -957,15 +960,13 @@ def lang_from_ext(cls, ext: str) -> SemanticSearchLanguage | None: | |
| Returns: | ||
| The corresponding SemanticSearchLanguage, or None if not found. | ||
| """ | ||
| return next( | ||
| ( | ||
| lang | ||
| for lang in cls | ||
| if lang.extensions | ||
| if next((extension for extension in lang.extensions if ext == extension), None) | ||
| ), | ||
| None, | ||
| ) | ||
| # Optimization: Loop with early return is significantly faster than next() generator comprehension | ||
| for lang in cls: | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. question (bug_risk): Consider normalizing
|
||
| if lang.extensions: | ||
| for extension in lang.extensions: | ||
| if ext == extension: | ||
| return lang | ||
| return None | ||
|
|
||
| @computed_field | ||
| @property | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
suggestion (typo): Use "generator expressions" instead of "generator comprehensions" for consistency with Python terminology.
The sentence ends with "on generator comprehensions" but earlier correctly uses "generator expression". Please update the closing phrase to "on generator expressions" to align with Pythonβs standard terminology and avoid confusion with list comprehensions.