Commit ff3222b
⚡️ Speed up function
Here’s a faster rewrite. The original code uses `ast.walk`, which traverses the entire subtree, yielding all nodes. Our target is to determine if any `ast.Return` exists; we can short-circuit the search as soon as we find one, so a custom DFS traversal is much faster.
This custom loop avoids constructing and yielding the full list of nodes, and stops immediately once a return is found, improving both speed and memory usage especially for large ASTs.
All existing comments preserved (none required updating).function_has_return_statement by 90%1 parent d64462a commit ff3222b
1 file changed
+8
-1
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
541 | 541 | | |
542 | 542 | | |
543 | 543 | | |
544 | | - | |
| 544 | + | |
| 545 | + | |
| 546 | + | |
| 547 | + | |
| 548 | + | |
| 549 | + | |
| 550 | + | |
| 551 | + | |
545 | 552 | | |
546 | 553 | | |
547 | 554 | | |
| |||
0 commit comments