Commit 01a1bf6
authored
Speed up the implementation of hasattr() checks (#14333)
This makes the implementation of hasattr() checks faster (introduced in
#13544).
In particular, since the `extra_attrs` attribute used for hasattr()
checks is usually None, I micro-optimized the codepaths to avoid
expensive operations whenever there are no hasattr() checks.
Also avoid expensive operations on simple unions and order `isinstance`
checks so that common types are checked first.
I measured a 2% performance uplift in self-check.1 parent c246a52 commit 01a1bf6
2 files changed
+29
-15
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
76 | 76 | | |
77 | 77 | | |
78 | 78 | | |
79 | | - | |
| 79 | + | |
80 | 80 | | |
81 | 81 | | |
82 | 82 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
33 | 33 | | |
34 | 34 | | |
35 | 35 | | |
| 36 | + | |
36 | 37 | | |
37 | 38 | | |
38 | 39 | | |
| |||
466 | 467 | | |
467 | 468 | | |
468 | 469 | | |
469 | | - | |
470 | | - | |
471 | | - | |
472 | | - | |
473 | | - | |
474 | | - | |
475 | | - | |
476 | | - | |
477 | | - | |
478 | | - | |
| 470 | + | |
| 471 | + | |
| 472 | + | |
| 473 | + | |
| 474 | + | |
| 475 | + | |
| 476 | + | |
| 477 | + | |
| 478 | + | |
| 479 | + | |
| 480 | + | |
| 481 | + | |
| 482 | + | |
| 483 | + | |
| 484 | + | |
| 485 | + | |
| 486 | + | |
| 487 | + | |
| 488 | + | |
| 489 | + | |
| 490 | + | |
479 | 491 | | |
480 | 492 | | |
481 | 493 | | |
| |||
1006 | 1018 | | |
1007 | 1019 | | |
1008 | 1020 | | |
1009 | | - | |
1010 | | - | |
1011 | | - | |
| 1021 | + | |
1012 | 1022 | | |
| 1023 | + | |
| 1024 | + | |
1013 | 1025 | | |
1014 | 1026 | | |
1015 | | - | |
| 1027 | + | |
| 1028 | + | |
| 1029 | + | |
1016 | 1030 | | |
1017 | 1031 | | |
1018 | 1032 | | |
| |||
0 commit comments