gh-150027: Avoid copying during construction of frozenset objects#150028
Merged
Conversation
markshannon
reviewed
May 18, 2026
Member
markshannon
left a comment
There was a problem hiding this comment.
Looks good in general.
Can you add a test to show that this is producing sensible bytecode?
| } | ||
|
|
||
| PyObject * | ||
| _PyFrozenSet_NewAndSteal(PyObject *set) |
Member
There was a problem hiding this comment.
Can you rename this to something that makes it explicit than it modifies the set.
Maybe _PySet_Freeze or something like that.
|
|
||
| expr_ty arg_expr = asdl_seq_GET(args, 0); | ||
|
|
||
| if (arg_expr->kind != GeneratorExp_kind) { |
Member
There was a problem hiding this comment.
Can you move this test after the body of this optimization:
if (_PyUnicode_EqualToASCIIString(func->v.Name.id, "frozenset") ...
...
}
if (arg_expr->kind != GeneratorExp_kind) {
return 0;
}
markshannon
approved these changes
May 19, 2026
Member
markshannon
left a comment
There was a problem hiding this comment.
Looks good, thanks.
I note that the code generating the argument to frozenset is duplicated.
This is a pre-existing issue with the way that maybe_optimize_function_call works.
We should fix that in a future PR.
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.
frozensetconstruction #150027