Repository navigation
Commit 0f32147
gh-87613: Use Argument Clinic vectorcall for xml.etree.ElementTree.Element
xml.etree.ElementTree.Element gains a generated vectorcall. Keys that
are not strings in `**extra` now raise TypeError on a normal call, as
the Python implementation already did, because vectorcall keywords must
be strings; an explicit `__init__` call and subclasses still accept them.
`@text_signature` keeps the documented `(tag, /, attrib={}, **extra)`:
`attrib` can still be passed by keyword, which the impl pops from `extra`.
Merging the keywords into the attributes now copies them with
PyDict_Copy() instead of PyDict_New() plus PyDict_Update(), and pops
`attrib` with `_Py_ID(attrib)` rather than creating a string per call;
SubElement shares that helper.
pyperf microbenchmark (PGO+LTO, run serially):
| Benchmark | base | Element |
|------------------------|:-------:|:---------------------:|
| E('a', x='1') | 116 ns | 76.3 ns: 1.52x faster |
| E('a') | 42.6 ns | 28.2 ns: 1.51x faster |
| E('a', attrib=d) | 122 ns | 82.8 ns: 1.47x faster |
| E('a', d) | 73.8 ns | 53.6 ns: 1.38x faster |
| SE(E('p'), 'a', x='1') | 161 ns | 120 ns: 1.35x faster |
| E('a', d, y='2') | 102 ns | 80.3 ns: 1.27x faster |
| S('a') | 49.4 ns | 39.8 ns: 1.24x faster |
Benchmark code:
```python
import pyperf
runner = pyperf.Runner()
setup = ("from _elementtree import Element as E, SubElement as SE\n"
"d = {'x': '1'}\n"
"class S(E): pass")
for stmt in ["E('a')", "E('a', d)", "E('a', x='1')", "E('a', d, y='2')",
"E('a', attrib=d)", "S('a')", "SE(E('p'), 'a', x='1')"]:
runner.timeit(stmt, stmt, setup)
```
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>1 parent 0461451 commit 0f32147
8 files changed
Lines changed: 161 additions & 50 deletions
File tree
- Include/internal
- Lib/test
- Misc/NEWS.d/next/Library
- Modules
- clinic
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
327 | 327 | | |
328 | 328 | | |
329 | 329 | | |
| 330 | + | |
330 | 331 | | |
331 | 332 | | |
332 | 333 | | |
| |||
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
3022 | 3022 | | |
3023 | 3023 | | |
3024 | 3024 | | |
| 3025 | + | |
| 3026 | + | |
| 3027 | + | |
| 3028 | + | |
3025 | 3029 | | |
3026 | 3030 | | |
3027 | 3031 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
19 | 19 | | |
20 | 20 | | |
21 | 21 | | |
| 22 | + | |
22 | 23 | | |
23 | 24 | | |
24 | 25 | | |
| |||
377 | 378 | | |
378 | 379 | | |
379 | 380 | | |
380 | | - | |
| 381 | + | |
381 | 382 | | |
382 | 383 | | |
383 | 384 | | |
| |||
393 | 394 | | |
394 | 395 | | |
395 | 396 | | |
| 397 | + | |
| 398 | + | |
| 399 | + | |
| 400 | + | |
| 401 | + | |
396 | 402 | | |
397 | | - | |
398 | | - | |
399 | | - | |
400 | | - | |
401 | | - | |
402 | | - | |
403 | | - | |
404 | | - | |
405 | | - | |
| 403 | + | |
406 | 404 | | |
407 | 405 | | |
408 | 406 | | |
| |||
413 | 411 | | |
414 | 412 | | |
415 | 413 | | |
| 414 | + | |
| 415 | + | |
| 416 | + | |
| 417 | + | |
| 418 | + | |
| 419 | + | |
| 420 | + | |
| 421 | + | |
| 422 | + | |
| 423 | + | |
| 424 | + | |
| 425 | + | |
| 426 | + | |
| 427 | + | |
| 428 | + | |
| 429 | + | |
| 430 | + | |
| 431 | + | |
| 432 | + | |
| 433 | + | |
| 434 | + | |
| 435 | + | |
| 436 | + | |
| 437 | + | |
| 438 | + | |
| 439 | + | |
416 | 440 | | |
417 | | - | |
| 441 | + | |
| 442 | + | |
| 443 | + | |
418 | 444 | | |
419 | | - | |
420 | | - | |
421 | | - | |
422 | | - | |
423 | | - | |
424 | | - | |
425 | 445 | | |
426 | 446 | | |
427 | 447 | | |
| |||
434 | 454 | | |
435 | 455 | | |
436 | 456 | | |
437 | | - | |
438 | | - | |
| 457 | + | |
| 458 | + | |
439 | 459 | | |
440 | 460 | | |
441 | 461 | | |
442 | 462 | | |
443 | | - | |
| 463 | + | |
444 | 464 | | |
445 | | - | |
| 465 | + | |
446 | 466 | | |
447 | 467 | | |
448 | 468 | | |
449 | 469 | | |
450 | | - | |
451 | | - | |
452 | 470 | | |
453 | | - | |
| 471 | + | |
454 | 472 | | |
455 | 473 | | |
456 | 474 | | |
| |||
460 | 478 | | |
461 | 479 | | |
462 | 480 | | |
463 | | - | |
| 481 | + | |
464 | 482 | | |
465 | | - | |
466 | | - | |
| 483 | + | |
| 484 | + | |
467 | 485 | | |
468 | 486 | | |
469 | 487 | | |
| |||
4451 | 4469 | | |
4452 | 4470 | | |
4453 | 4471 | | |
4454 | | - | |
4455 | | - | |
4456 | | - | |
4457 | | - | |
4458 | | - | |
4459 | | - | |
4460 | | - | |
4461 | | - | |
4462 | | - | |
4463 | | - | |
4464 | | - | |
4465 | | - | |
4466 | | - | |
4467 | | - | |
4468 | | - | |
4469 | | - | |
4470 | | - | |
4471 | | - | |
4472 | | - | |
4473 | 4472 | | |
4474 | | - | |
| 4473 | + | |
4475 | 4474 | | |
4476 | 4475 | | |
4477 | 4476 | | |
| |||
4480 | 4479 | | |
4481 | 4480 | | |
4482 | 4481 | | |
4483 | | - | |
| 4482 | + | |
| 4483 | + | |
4484 | 4484 | | |
4485 | 4485 | | |
4486 | 4486 | | |
| |||
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
0 commit comments