You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Here’s an optimized rewrite focusing on.
- **Avoiding repeated list/dict construction:** Replaces `["FunctionDef", "AsyncFunctionDef"]` with a `set` and a local variable for quick lookup.
- **Decorator matching:** Replaces the for-loop with a single pass using generator expression – thus returning immediately when a match is found, and avoiding extra checks.
- **Parent type check:** Caches `parents[0].type` in a variable.
- **Reduces function calls:** Pulls common checks out of loops.
Here's the optimized code (existing comments are unchanged, since logic is nearly the same).
### Summary of improvements.
- Eliminate duplicated string list creation per call.
- Save parents[0].type only once
- Early returns in the decorator loop; avoids further iteration if not necessary.
This should speed up your function, especially under heavy use!
0 commit comments