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

Skip to content

Commit 3267f87

Browse files
committed
Remove special-casing of integer operations, to stop
using PyInt_CheckExact.
1 parent 8b0facf commit 3267f87

1 file changed

Lines changed: 6 additions & 91 deletions

File tree

Python/ceval.c

Lines changed: 6 additions & 91 deletions
Original file line numberDiff line numberDiff line change
@@ -1118,24 +1118,13 @@ PyEval_EvalFrameEx(PyFrameObject *f, int throwflag)
11181118
case BINARY_ADD:
11191119
w = POP();
11201120
v = TOP();
1121-
if (PyInt_CheckExact(v) && PyInt_CheckExact(w)) {
1122-
/* INLINE: int + int */
1123-
register long a, b, i;
1124-
a = PyLong_AS_LONG(v);
1125-
b = PyLong_AS_LONG(w);
1126-
i = a + b;
1127-
if ((i^a) < 0 && (i^b) < 0)
1128-
goto slow_add;
1129-
x = PyLong_FromLong(i);
1130-
}
1131-
else if (PyUnicode_CheckExact(v) &&
1121+
if (PyUnicode_CheckExact(v) &&
11321122
PyUnicode_CheckExact(w)) {
11331123
x = unicode_concatenate(v, w, f, next_instr);
11341124
/* unicode_concatenate consumed the ref to v */
11351125
goto skip_decref_vx;
11361126
}
11371127
else {
1138-
slow_add:
11391128
x = PyNumber_Add(v, w);
11401129
}
11411130
Py_DECREF(v);
@@ -1148,20 +1137,7 @@ PyEval_EvalFrameEx(PyFrameObject *f, int throwflag)
11481137
case BINARY_SUBTRACT:
11491138
w = POP();
11501139
v = TOP();
1151-
if (PyInt_CheckExact(v) && PyInt_CheckExact(w)) {
1152-
/* INLINE: int - int */
1153-
register long a, b, i;
1154-
a = PyLong_AS_LONG(v);
1155-
b = PyLong_AS_LONG(w);
1156-
i = a - b;
1157-
if ((i^a) < 0 && (i^~b) < 0)
1158-
goto slow_sub;
1159-
x = PyLong_FromLong(i);
1160-
}
1161-
else {
1162-
slow_sub:
1163-
x = PyNumber_Subtract(v, w);
1164-
}
1140+
x = PyNumber_Subtract(v, w);
11651141
Py_DECREF(v);
11661142
Py_DECREF(w);
11671143
SET_TOP(x);
@@ -1171,21 +1147,7 @@ PyEval_EvalFrameEx(PyFrameObject *f, int throwflag)
11711147
case BINARY_SUBSCR:
11721148
w = POP();
11731149
v = TOP();
1174-
if (PyList_CheckExact(v) && PyInt_CheckExact(w)) {
1175-
/* INLINE: list[int] */
1176-
Py_ssize_t i = PyLong_AsSsize_t(w);
1177-
if (i < 0)
1178-
i += PyList_GET_SIZE(v);
1179-
if (i >= 0 && i < PyList_GET_SIZE(v)) {
1180-
x = PyList_GET_ITEM(v, i);
1181-
Py_INCREF(x);
1182-
}
1183-
else
1184-
goto slow_get;
1185-
}
1186-
else
1187-
slow_get:
1188-
x = PyObject_GetItem(v, w);
1150+
x = PyObject_GetItem(v, w);
11891151
Py_DECREF(v);
11901152
Py_DECREF(w);
11911153
SET_TOP(x);
@@ -1319,24 +1281,13 @@ PyEval_EvalFrameEx(PyFrameObject *f, int throwflag)
13191281
case INPLACE_ADD:
13201282
w = POP();
13211283
v = TOP();
1322-
if (PyInt_CheckExact(v) && PyInt_CheckExact(w)) {
1323-
/* INLINE: int + int */
1324-
register long a, b, i;
1325-
a = PyLong_AS_LONG(v);
1326-
b = PyLong_AS_LONG(w);
1327-
i = a + b;
1328-
if ((i^a) < 0 && (i^b) < 0)
1329-
goto slow_iadd;
1330-
x = PyLong_FromLong(i);
1331-
}
1332-
else if (PyUnicode_CheckExact(v) &&
1284+
if (PyUnicode_CheckExact(v) &&
13331285
PyUnicode_CheckExact(w)) {
13341286
x = unicode_concatenate(v, w, f, next_instr);
13351287
/* unicode_concatenate consumed the ref to v */
13361288
goto skip_decref_v;
13371289
}
13381290
else {
1339-
slow_iadd:
13401291
x = PyNumber_InPlaceAdd(v, w);
13411292
}
13421293
Py_DECREF(v);
@@ -1349,20 +1300,7 @@ PyEval_EvalFrameEx(PyFrameObject *f, int throwflag)
13491300
case INPLACE_SUBTRACT:
13501301
w = POP();
13511302
v = TOP();
1352-
if (PyInt_CheckExact(v) && PyInt_CheckExact(w)) {
1353-
/* INLINE: int - int */
1354-
register long a, b, i;
1355-
a = PyLong_AS_LONG(v);
1356-
b = PyLong_AS_LONG(w);
1357-
i = a - b;
1358-
if ((i^a) < 0 && (i^~b) < 0)
1359-
goto slow_isub;
1360-
x = PyLong_FromLong(i);
1361-
}
1362-
else {
1363-
slow_isub:
1364-
x = PyNumber_InPlaceSubtract(v, w);
1365-
}
1303+
x = PyNumber_InPlaceSubtract(v, w);
13661304
Py_DECREF(v);
13671305
Py_DECREF(w);
13681306
SET_TOP(x);
@@ -1865,30 +1803,7 @@ PyEval_EvalFrameEx(PyFrameObject *f, int throwflag)
18651803
case COMPARE_OP:
18661804
w = POP();
18671805
v = TOP();
1868-
if (PyInt_CheckExact(w) && PyInt_CheckExact(v)) {
1869-
/* INLINE: cmp(int, int) */
1870-
register long a, b;
1871-
register int res;
1872-
a = PyLong_AS_LONG(v);
1873-
b = PyLong_AS_LONG(w);
1874-
switch (oparg) {
1875-
case PyCmp_LT: res = a < b; break;
1876-
case PyCmp_LE: res = a <= b; break;
1877-
case PyCmp_EQ: res = a == b; break;
1878-
case PyCmp_NE: res = a != b; break;
1879-
case PyCmp_GT: res = a > b; break;
1880-
case PyCmp_GE: res = a >= b; break;
1881-
case PyCmp_IS: res = v == w; break;
1882-
case PyCmp_IS_NOT: res = v != w; break;
1883-
default: goto slow_compare;
1884-
}
1885-
x = res ? Py_True : Py_False;
1886-
Py_INCREF(x);
1887-
}
1888-
else {
1889-
slow_compare:
1890-
x = cmp_outcome(oparg, v, w);
1891-
}
1806+
x = cmp_outcome(oparg, v, w);
18921807
Py_DECREF(v);
18931808
Py_DECREF(w);
18941809
SET_TOP(x);

0 commit comments

Comments
 (0)