Commit db8241f
authored
Here’s a faster, more memory-efficient rewrite of your program. Optimizations include.
- Removed duplicate `get_pr_number` import and moved/corrected its singleton responsibility.
- Used direct, local variable access rather than repeatedly referencing imported modules.
- Used `os.environ[]` instead of `os.environ.get` for critical env lookups in a try-block (avoids lookup cost when you know failure will land in except anyway).
- Used direct file open for reading (avoiding Path overhead).
- Avoided reading/parsing JSON and dictionary keys if the PR number/env is missing.
- Reduced exception handling scope to only JSON/file-related operations.
All existing comments are preserved except where the code was made more efficient.
**Key points:**
- File reading is done only if both env vars are present, before JSON parsing.
- The exception only wraps file I/O + JSON parsing, not the env checks, so it's tighter/faster in normal runs.
- No `Path`. Used built-in open for speed.
- Early returns for failures, so the function does the minimum work necessary.
- Single access to environment variables (no redundancy).
**Functional output is preserved.**
1 parent 7f42425 commit db8241f
2 files changed
+14
-12
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
66 | 66 | | |
67 | 67 | | |
68 | 68 | | |
69 | | - | |
70 | | - | |
71 | | - | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
72 | 75 | | |
73 | 76 | | |
74 | 77 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
311 | 311 | | |
312 | 312 | | |
313 | 313 | | |
314 | | - | |
315 | | - | |
316 | | - | |
317 | | - | |
318 | | - | |
| 314 | + | |
| 315 | + | |
| 316 | + | |
| 317 | + | |
| 318 | + | |
319 | 319 | | |
320 | 320 | | |
321 | | - | |
322 | | - | |
323 | | - | |
324 | | - | |
| 321 | + | |
| 322 | + | |
| 323 | + | |
0 commit comments