mirror of
https://github.com/python/cpython.git
synced 2025-08-03 16:39:00 +00:00
GH-101291: Refactor the PyLongObject
struct into object header and PyLongValue struct. (GH-101292)
This commit is contained in:
parent
f5a3d91b6c
commit
c1b1f51cd1
13 changed files with 226 additions and 217 deletions
|
@ -2507,10 +2507,10 @@ builtin_sum_impl(PyObject *module, PyObject *iterable, PyObject *start)
|
|||
overflow = 0;
|
||||
/* Single digits are common, fast, and cannot overflow on unpacking. */
|
||||
switch (Py_SIZE(item)) {
|
||||
case -1: b = -(sdigit) ((PyLongObject*)item)->ob_digit[0]; break;
|
||||
case -1: b = -(sdigit) ((PyLongObject*)item)->long_value.ob_digit[0]; break;
|
||||
// Note: the continue goes to the top of the "while" loop that iterates over the elements
|
||||
case 0: Py_DECREF(item); continue;
|
||||
case 1: b = ((PyLongObject*)item)->ob_digit[0]; break;
|
||||
case 1: b = ((PyLongObject*)item)->long_value.ob_digit[0]; break;
|
||||
default: b = PyLong_AsLongAndOverflow(item, &overflow); break;
|
||||
}
|
||||
if (overflow == 0 &&
|
||||
|
|
|
@ -357,8 +357,8 @@ dummy_func(
|
|||
|
||||
// Deopt unless 0 <= sub < PyList_Size(list)
|
||||
DEOPT_IF(!_PyLong_IsPositiveSingleDigit(sub), BINARY_SUBSCR);
|
||||
assert(((PyLongObject *)_PyLong_GetZero())->ob_digit[0] == 0);
|
||||
Py_ssize_t index = ((PyLongObject*)sub)->ob_digit[0];
|
||||
assert(((PyLongObject *)_PyLong_GetZero())->long_value.ob_digit[0] == 0);
|
||||
Py_ssize_t index = ((PyLongObject*)sub)->long_value.ob_digit[0];
|
||||
DEOPT_IF(index >= PyList_GET_SIZE(list), BINARY_SUBSCR);
|
||||
STAT_INC(BINARY_SUBSCR, hit);
|
||||
res = PyList_GET_ITEM(list, index);
|
||||
|
@ -375,8 +375,8 @@ dummy_func(
|
|||
|
||||
// Deopt unless 0 <= sub < PyTuple_Size(list)
|
||||
DEOPT_IF(!_PyLong_IsPositiveSingleDigit(sub), BINARY_SUBSCR);
|
||||
assert(((PyLongObject *)_PyLong_GetZero())->ob_digit[0] == 0);
|
||||
Py_ssize_t index = ((PyLongObject*)sub)->ob_digit[0];
|
||||
assert(((PyLongObject *)_PyLong_GetZero())->long_value.ob_digit[0] == 0);
|
||||
Py_ssize_t index = ((PyLongObject*)sub)->long_value.ob_digit[0];
|
||||
DEOPT_IF(index >= PyTuple_GET_SIZE(tuple), BINARY_SUBSCR);
|
||||
STAT_INC(BINARY_SUBSCR, hit);
|
||||
res = PyTuple_GET_ITEM(tuple, index);
|
||||
|
@ -469,7 +469,7 @@ dummy_func(
|
|||
|
||||
// Ensure nonnegative, zero-or-one-digit ints.
|
||||
DEOPT_IF(!_PyLong_IsPositiveSingleDigit(sub), STORE_SUBSCR);
|
||||
Py_ssize_t index = ((PyLongObject*)sub)->ob_digit[0];
|
||||
Py_ssize_t index = ((PyLongObject*)sub)->long_value.ob_digit[0];
|
||||
// Ensure index < len(list)
|
||||
DEOPT_IF(index >= PyList_GET_SIZE(list), STORE_SUBSCR);
|
||||
STAT_INC(STORE_SUBSCR, hit);
|
||||
|
@ -1834,8 +1834,8 @@ dummy_func(
|
|||
DEOPT_IF((size_t)(Py_SIZE(right) + 1) > 2, COMPARE_AND_BRANCH);
|
||||
STAT_INC(COMPARE_AND_BRANCH, hit);
|
||||
assert(Py_ABS(Py_SIZE(left)) <= 1 && Py_ABS(Py_SIZE(right)) <= 1);
|
||||
Py_ssize_t ileft = Py_SIZE(left) * ((PyLongObject *)left)->ob_digit[0];
|
||||
Py_ssize_t iright = Py_SIZE(right) * ((PyLongObject *)right)->ob_digit[0];
|
||||
Py_ssize_t ileft = Py_SIZE(left) * ((PyLongObject *)left)->long_value.ob_digit[0];
|
||||
Py_ssize_t iright = Py_SIZE(right) * ((PyLongObject *)right)->long_value.ob_digit[0];
|
||||
// 2 if <, 4 if >, 8 if ==; this matches the low 4 bits of the oparg
|
||||
int sign_ish = COMPARISON_BIT(ileft, iright);
|
||||
_Py_DECREF_SPECIALIZED(left, (destructor)PyObject_Free);
|
||||
|
|
14
Python/generated_cases.c.h
generated
14
Python/generated_cases.c.h
generated
|
@ -484,8 +484,8 @@
|
|||
|
||||
// Deopt unless 0 <= sub < PyList_Size(list)
|
||||
DEOPT_IF(!_PyLong_IsPositiveSingleDigit(sub), BINARY_SUBSCR);
|
||||
assert(((PyLongObject *)_PyLong_GetZero())->ob_digit[0] == 0);
|
||||
Py_ssize_t index = ((PyLongObject*)sub)->ob_digit[0];
|
||||
assert(((PyLongObject *)_PyLong_GetZero())->long_value.ob_digit[0] == 0);
|
||||
Py_ssize_t index = ((PyLongObject*)sub)->long_value.ob_digit[0];
|
||||
DEOPT_IF(index >= PyList_GET_SIZE(list), BINARY_SUBSCR);
|
||||
STAT_INC(BINARY_SUBSCR, hit);
|
||||
res = PyList_GET_ITEM(list, index);
|
||||
|
@ -509,8 +509,8 @@
|
|||
|
||||
// Deopt unless 0 <= sub < PyTuple_Size(list)
|
||||
DEOPT_IF(!_PyLong_IsPositiveSingleDigit(sub), BINARY_SUBSCR);
|
||||
assert(((PyLongObject *)_PyLong_GetZero())->ob_digit[0] == 0);
|
||||
Py_ssize_t index = ((PyLongObject*)sub)->ob_digit[0];
|
||||
assert(((PyLongObject *)_PyLong_GetZero())->long_value.ob_digit[0] == 0);
|
||||
Py_ssize_t index = ((PyLongObject*)sub)->long_value.ob_digit[0];
|
||||
DEOPT_IF(index >= PyTuple_GET_SIZE(tuple), BINARY_SUBSCR);
|
||||
STAT_INC(BINARY_SUBSCR, hit);
|
||||
res = PyTuple_GET_ITEM(tuple, index);
|
||||
|
@ -634,7 +634,7 @@
|
|||
|
||||
// Ensure nonnegative, zero-or-one-digit ints.
|
||||
DEOPT_IF(!_PyLong_IsPositiveSingleDigit(sub), STORE_SUBSCR);
|
||||
Py_ssize_t index = ((PyLongObject*)sub)->ob_digit[0];
|
||||
Py_ssize_t index = ((PyLongObject*)sub)->long_value.ob_digit[0];
|
||||
// Ensure index < len(list)
|
||||
DEOPT_IF(index >= PyList_GET_SIZE(list), STORE_SUBSCR);
|
||||
STAT_INC(STORE_SUBSCR, hit);
|
||||
|
@ -2179,8 +2179,8 @@
|
|||
DEOPT_IF((size_t)(Py_SIZE(right) + 1) > 2, COMPARE_AND_BRANCH);
|
||||
STAT_INC(COMPARE_AND_BRANCH, hit);
|
||||
assert(Py_ABS(Py_SIZE(left)) <= 1 && Py_ABS(Py_SIZE(right)) <= 1);
|
||||
Py_ssize_t ileft = Py_SIZE(left) * ((PyLongObject *)left)->ob_digit[0];
|
||||
Py_ssize_t iright = Py_SIZE(right) * ((PyLongObject *)right)->ob_digit[0];
|
||||
Py_ssize_t ileft = Py_SIZE(left) * ((PyLongObject *)left)->long_value.ob_digit[0];
|
||||
Py_ssize_t iright = Py_SIZE(right) * ((PyLongObject *)right)->long_value.ob_digit[0];
|
||||
// 2 if <, 4 if >, 8 if ==; this matches the low 4 bits of the oparg
|
||||
int sign_ish = COMPARISON_BIT(ileft, iright);
|
||||
_Py_DECREF_SPECIALIZED(left, (destructor)PyObject_Free);
|
||||
|
|
|
@ -240,7 +240,7 @@ w_PyLong(const PyLongObject *ob, char flag, WFILE *p)
|
|||
/* set l to number of base PyLong_MARSHAL_BASE digits */
|
||||
n = Py_ABS(Py_SIZE(ob));
|
||||
l = (n-1) * PyLong_MARSHAL_RATIO;
|
||||
d = ob->ob_digit[n-1];
|
||||
d = ob->long_value.ob_digit[n-1];
|
||||
assert(d != 0); /* a PyLong is always normalized */
|
||||
do {
|
||||
d >>= PyLong_MARSHAL_SHIFT;
|
||||
|
@ -254,14 +254,14 @@ w_PyLong(const PyLongObject *ob, char flag, WFILE *p)
|
|||
w_long((long)(Py_SIZE(ob) > 0 ? l : -l), p);
|
||||
|
||||
for (i=0; i < n-1; i++) {
|
||||
d = ob->ob_digit[i];
|
||||
d = ob->long_value.ob_digit[i];
|
||||
for (j=0; j < PyLong_MARSHAL_RATIO; j++) {
|
||||
w_short(d & PyLong_MARSHAL_MASK, p);
|
||||
d >>= PyLong_MARSHAL_SHIFT;
|
||||
}
|
||||
assert (d == 0);
|
||||
}
|
||||
d = ob->ob_digit[n-1];
|
||||
d = ob->long_value.ob_digit[n-1];
|
||||
do {
|
||||
w_short(d & PyLong_MARSHAL_MASK, p);
|
||||
d >>= PyLong_MARSHAL_SHIFT;
|
||||
|
@ -853,7 +853,7 @@ r_PyLong(RFILE *p)
|
|||
goto bad_digit;
|
||||
d += (digit)md << j*PyLong_MARSHAL_SHIFT;
|
||||
}
|
||||
ob->ob_digit[i] = d;
|
||||
ob->long_value.ob_digit[i] = d;
|
||||
}
|
||||
|
||||
d = 0;
|
||||
|
@ -880,7 +880,7 @@ r_PyLong(RFILE *p)
|
|||
}
|
||||
/* top digit should be nonzero, else the resulting PyLong won't be
|
||||
normalized */
|
||||
ob->ob_digit[size-1] = d;
|
||||
ob->long_value.ob_digit[size-1] = d;
|
||||
return (PyObject *)ob;
|
||||
bad_digit:
|
||||
Py_DECREF(ob);
|
||||
|
|
|
@ -1411,7 +1411,7 @@ _Py_Specialize_StoreSubscr(PyObject *container, PyObject *sub, _Py_CODEUNIT *ins
|
|||
if (container_type == &PyList_Type) {
|
||||
if (PyLong_CheckExact(sub)) {
|
||||
if ((Py_SIZE(sub) == 0 || Py_SIZE(sub) == 1)
|
||||
&& ((PyLongObject *)sub)->ob_digit[0] < (size_t)PyList_GET_SIZE(container))
|
||||
&& ((PyLongObject *)sub)->long_value.ob_digit[0] < (size_t)PyList_GET_SIZE(container))
|
||||
{
|
||||
_py_set_opcode(instr, STORE_SUBSCR_LIST_INT);
|
||||
goto success;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue