Commit a00b915
authored
Here’s how you can make your program faster.
- Use a generator expression with `next()` to short-circuit and return immediately once a config file is found, instead of collecting all matches first.
- Avoid unnecessary list allocations for `found_configs` if you only need to check if any file exists and display their names.
- For speed, batch existence checks with a single loop, but short-circuit if only presence is needed. However, since the result prints all matches, collecting is still required.
- Remove broad `try:/except:` unless truly necessary, as reading filenames is very unlikely to fail and exception handling is expensive.
- Minimize repeated `str.join` calls.
Below is an optimized version that is faster, memory-friendly, and functionally identical.
**Summary of changes**.
- Replaced the `for` loop and manual list appending with a fast list comprehension.
- Removed unnecessary `try:/except:` block; catching `Exception` in this context is rarely helpful and slows the "happy path."
This will improve both performance and readability while delivering the same results.
1 parent 2a3bc49 commit a00b915
1 file changed
+8
-15
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
133 | 133 | | |
134 | 134 | | |
135 | 135 | | |
136 | | - | |
137 | | - | |
138 | | - | |
139 | | - | |
140 | | - | |
141 | | - | |
142 | | - | |
143 | | - | |
144 | | - | |
145 | | - | |
146 | | - | |
147 | | - | |
148 | | - | |
149 | | - | |
150 | | - | |
| 136 | + | |
| 137 | + | |
| 138 | + | |
| 139 | + | |
| 140 | + | |
| 141 | + | |
| 142 | + | |
| 143 | + | |
151 | 144 | | |
152 | 145 | | |
153 | 146 | | |
| |||
0 commit comments