-
-
Notifications
You must be signed in to change notification settings - Fork 34.3k
Closed
Labels
interpreter-core(Objects, Python, Grammar, and Parser dirs)(Objects, Python, Grammar, and Parser dirs)type-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error
Description
Right now there's a special case in handling this opcode:
Lines 3060 to 3073 in 5ffdaf7
| /* If value is a unicode object, and there's no fmt_spec, | |
| then we know the result of format(value) is value | |
| itself. In that case, skip calling format(). I plan to | |
| move this optimization in to PyObject_Format() | |
| itself. */ | |
| if (PyUnicode_CheckExact(value) && fmt_spec == NULL) { | |
| /* Do nothing, just transfer ownership to result. */ | |
| result = value; | |
| } else { | |
| /* Actually call format(). */ | |
| result = PyObject_Format(value, fmt_spec); | |
| Py_DECREF(value); | |
| Py_XDECREF(fmt_spec); | |
| ERROR_IF(result == NULL, error); |
It comes from older version of ceval.c:
Lines 4379 to 4395 in 2810787
| /* If value is a unicode object, and there's no fmt_spec, | |
| then we know the result of format(value) is value | |
| itself. In that case, skip calling format(). I plan to | |
| move this optimization in to PyObject_Format() | |
| itself. */ | |
| if (PyUnicode_CheckExact(value) && fmt_spec == NULL) { | |
| /* Do nothing, just transfer ownership to result. */ | |
| result = value; | |
| } else { | |
| /* Actually call format(). */ | |
| result = PyObject_Format(value, fmt_spec); | |
| Py_DECREF(value); | |
| Py_XDECREF(fmt_spec); | |
| if (result == NULL) { | |
| goto error; | |
| } | |
| } |
But, I think that the needed optimizaion is there:
Lines 774 to 777 in 5ffdaf7
| if (format_spec == NULL || PyUnicode_GET_LENGTH(format_spec) == 0) { | |
| if (PyUnicode_CheckExact(obj)) { | |
| return Py_NewRef(obj); | |
| } |
So, I think this can be safely removed.
I will send a PR.
Linked PRs
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
interpreter-core(Objects, Python, Grammar, and Parser dirs)(Objects, Python, Grammar, and Parser dirs)type-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error