mirror of
https://github.com/python/cpython.git
synced 2025-11-26 21:33:10 +00:00
GH-107596: Specialize str[int] (GH-107597)
This commit is contained in:
parent
aab6f7173a
commit
ea72c6fe3b
10 changed files with 172 additions and 97 deletions
24
Python/generated_cases.c.h
generated
24
Python/generated_cases.c.h
generated
|
|
@ -685,6 +685,30 @@
|
|||
DISPATCH();
|
||||
}
|
||||
|
||||
TARGET(BINARY_SUBSCR_STR_INT) {
|
||||
PyObject *sub;
|
||||
PyObject *str;
|
||||
PyObject *res;
|
||||
sub = stack_pointer[-1];
|
||||
str = stack_pointer[-2];
|
||||
DEOPT_IF(!PyLong_CheckExact(sub), BINARY_SUBSCR);
|
||||
DEOPT_IF(!PyUnicode_CheckExact(str), BINARY_SUBSCR);
|
||||
DEOPT_IF(!_PyLong_IsNonNegativeCompact((PyLongObject *)sub), BINARY_SUBSCR);
|
||||
Py_ssize_t index = ((PyLongObject*)sub)->long_value.ob_digit[0];
|
||||
DEOPT_IF(PyUnicode_GET_LENGTH(str) <= index, BINARY_SUBSCR);
|
||||
// Specialize for reading an ASCII character from any string:
|
||||
Py_UCS4 c = PyUnicode_READ_CHAR(str, index);
|
||||
DEOPT_IF(Py_ARRAY_LENGTH(_Py_SINGLETON(strings).ascii) <= c, BINARY_SUBSCR);
|
||||
STAT_INC(BINARY_SUBSCR, hit);
|
||||
res = (PyObject*)&_Py_SINGLETON(strings).ascii[c];
|
||||
_Py_DECREF_SPECIALIZED(sub, (destructor)PyObject_Free);
|
||||
Py_DECREF(str);
|
||||
STACK_SHRINK(1);
|
||||
stack_pointer[-1] = res;
|
||||
next_instr += 1;
|
||||
DISPATCH();
|
||||
}
|
||||
|
||||
TARGET(BINARY_SUBSCR_TUPLE_INT) {
|
||||
PyObject *sub;
|
||||
PyObject *tuple;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue