Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Simplify code
  • Loading branch information
tomasr8 committed Apr 24, 2025
commit 0a96b3a14fb8805da18a83584e02f069a2cf84cb
7 changes: 3 additions & 4 deletions Python/optimizer_bytecodes.c
Original file line number Diff line number Diff line change
Expand Up @@ -856,10 +856,9 @@ dummy_func(void) {
}

op(_CALL_STR_1, (unused, unused, arg -- res)) {
if (sym_matches_type(arg, &PyUnicode_Type) && sym_is_const(ctx, arg)) {
// e.g. str('foo') or str(foo) where foo is known to be a string const
PyObject *value = sym_get_const(ctx, arg);
res = sym_new_const(ctx, value);
if (sym_matches_type(arg, &PyUnicode_Type)) {
// e.g. str('foo') or str(foo) where foo is known to be a string
res = arg;
}
Comment on lines +859 to +862
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is an optimization that Brandt suggested. When in str(foo), foo is known to be a string, we can propagate it to the output. I also added a test for this case.

else {
res = sym_new_type(ctx, &PyUnicode_Type);
Expand Down
5 changes: 2 additions & 3 deletions Python/optimizer_cases.c.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.