Commit 6ac7616
authored
⚡️ 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 60af8b7 commit 6ac7616
1 file changed
+12
-5
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
158 | 158 | | |
159 | 159 | | |
160 | 160 | | |
161 | | - | |
162 | | - | |
163 | | - | |
| 161 | + | |
| 162 | + | |
| 163 | + | |
164 | 164 | | |
165 | 165 | | |
166 | 166 | | |
| |||
207 | 207 | | |
208 | 208 | | |
209 | 209 | | |
210 | | - | |
| 210 | + | |
211 | 211 | | |
212 | 212 | | |
213 | 213 | | |
| |||
539 | 539 | | |
540 | 540 | | |
541 | 541 | | |
542 | | - | |
| 542 | + | |
| 543 | + | |
| 544 | + | |
| 545 | + | |
| 546 | + | |
| 547 | + | |
| 548 | + | |
| 549 | + | |
543 | 550 | | |
544 | 551 | | |
545 | 552 | | |
| |||
0 commit comments