Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork34.2k
gh-141510: Optimize frozendict(frozendict)#145592
gh-141510: Optimize frozendict(frozendict)#145592vstinner wants to merge 4 commits intopython:mainfrom
Conversation
Return the same object unmodified if it's exactly the frozendicttype.
vstinner commentedMar 6, 2026
cc@encukou |
| if (PyFrozenDict_CheckExact(iterable)) { | ||
| // PyFrozenDict_New(frozendict) returns the same object unmodified | ||
| returnPy_NewRef(iterable); | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
This is how I'd like it, but do note thatPyTuple_New orPyFrozenSet_New will always return a new object.
It's probably worth noting this in documentation.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
Hmm, usually we don't document such optimization, but ok, I added it toPyFrozenDict_New() documentation as a "CPython implementation detail".
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
Why document it if it is an internal implementation detail anyways? It gives the wrong sense that users can rely on this in CPython
Uh oh!
There was an error while loading.Please reload this page.
Return the same object unmodified if it's exactly the frozendict type.