Repository navigation
Commit 7305371
gh-159446: Avoid TypeError on FielIO construction
FileIO can be constructed off a string or an integer file descriptor.
It used PyLong_AsInt first to check "is this a integer". That raised a
TypeError when passed a string which would then be silenced. Proactively
check if it is a number with _PyIndex_Check saving instructions in the
common filename path.
Callgrind, instructions per `FileIO(path).readall()` + `close()` of a
111-byte file:
| Build | base | this change |
|------------------|-------:|------------:|
| PGO+LTO | 10,641 | 8,918 |
| -O3, no PGO | 14,154 | 12,016 |
pyperf, the same on a 182-byte file, PGO+LTO, 4 interleaved rounds of
10 processes:
| Benchmark | base | this change |
|----------------|:-------:|:---------------------:|
| fileio_readall | 3.71 us | 3.62 us: 1.02x faster |
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>1 parent 637fb36 commit 7305371
1 file changed
Lines changed: 11 additions & 7 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | 2 | | |
3 | 3 | | |
| 4 | + | |
4 | 5 | | |
5 | 6 | | |
6 | 7 | | |
| |||
300 | 301 | | |
301 | 302 | | |
302 | 303 | | |
303 | | - | |
304 | | - | |
305 | | - | |
306 | | - | |
307 | | - | |
308 | | - | |
| 304 | + | |
| 305 | + | |
| 306 | + | |
| 307 | + | |
| 308 | + | |
| 309 | + | |
| 310 | + | |
| 311 | + | |
| 312 | + | |
| 313 | + | |
309 | 314 | | |
310 | | - | |
311 | 315 | | |
312 | 316 | | |
313 | 317 | | |
| |||
0 commit comments