gh-144140: Optimize len for frozen dict/set constants in optimizer (#149969)

This commit is contained in:
Lukas Geiger 2026-05-18 07:50:42 +01:00 committed by GitHub
parent 6ee879ffa1
commit 18281db0d0
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 20 additions and 8 deletions

View file

@ -2378,7 +2378,7 @@ dummy_func(void) {
res = sym_new_type(ctx, &PyLong_Type);
Py_ssize_t length = sym_tuple_length(arg);
// Not a tuple, check if it's a const string
// Not a tuple, check if it's another immutable const with known length
if (length < 0 && sym_is_const(ctx, arg)) {
PyObject *const_val = sym_get_const(ctx, arg);
if (const_val != NULL) {
@ -2388,6 +2388,12 @@ dummy_func(void) {
else if (PyBytes_CheckExact(const_val)) {
length = PyBytes_GET_SIZE(const_val);
}
else if (PyFrozenDict_CheckExact(const_val)) {
length = PyDict_GET_SIZE(const_val);
}
else if (PyFrozenSet_CheckExact(const_val)) {
length = PySet_GET_SIZE(const_val);
}
}
}