Skip to content

gh-158863: Drop redundant incref/decref pair in dict_dict_merge() - #158864

Merged
eendebakpt merged 1 commit into
python:mainfrom
eendebakpt:dict-merge-drop-incref
Oct 6, 2026
Merged

eendebakpt merged 1 commit into
python:mainfrom
eendebakpt:dict-merge-drop-incref

Conversation

@eendebakpt

@eendebakpt eendebakpt commented Oct 5, 2026 •

Copy link
Copy Markdown
Contributor

For details see the corresponding issue.

On the override path insertdict() receives its own references to key
and value via Py_NewRef(), and nothing in the loop body uses them
afterwards, so the outer Py_INCREF/Py_DECREF pair was pure overhead.
Keep it only on the non-override path, where _PyDict_Contains_KnownHash()
can run arbitrary __eq__ code and *dupkey needs a live reference.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
@eendebakpt
eendebakpt merged commit 82c62ab into python:main Oct 6, 2026
58 of 62 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

skip news type-feature A feature request or enhancement

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants