gh-141510: Optimize frozendict(frozendict)#145592
Open
vstinner wants to merge 4 commits intopython:mainfrom
Open
gh-141510: Optimize frozendict(frozendict)#145592vstinner wants to merge 4 commits intopython:mainfrom
vstinner wants to merge 4 commits intopython:mainfrom
Conversation
Return the same object unmodified if it's exactly the frozendict type.
Member
Author
|
cc @encukou |
encukou
reviewed
Mar 6, 2026
Comment on lines
+8206
to
+8209
| if (PyFrozenDict_CheckExact(iterable)) { | ||
| // PyFrozenDict_New(frozendict) returns the same object unmodified | ||
| return Py_NewRef(iterable); | ||
| } |
Member
There was a problem hiding this comment.
This is how I'd like it, but do note that PyTuple_New or PyFrozenSet_New will always return a new object.
It's probably worth noting this in documentation.
Member
Author
There was a problem hiding this comment.
Hmm, usually we don't document such optimization, but ok, I added it to PyFrozenDict_New() documentation as a "CPython implementation detail".
Contributor
There was a problem hiding this comment.
Why document it if it is an internal implementation detail anyways? It gives the wrong sense that users can rely on this in CPython
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Return the same object unmodified if it's exactly the frozendict type.