Mercurial > cpython-lru_cache-weakref
comparison Python/ceval.c @ 44156:fb84bd9500a4
Remove special-casing of integer operations, to stop
using PyInt_CheckExact.
| author | Martin v. Löwis <martin@v.loewis.de> |
|---|---|
| date | Tue, 04 Dec 2007 20:34:12 +0000 |
| parents | f324631462a2 |
| children | 81e0c0e2a8c1 |
comparison
equal
deleted
inserted
replaced
| 44155:1a2a6df0fbe0 | 44156:fb84bd9500a4 |
|---|---|
| 1116 break; | 1116 break; |
| 1117 | 1117 |
| 1118 case BINARY_ADD: | 1118 case BINARY_ADD: |
| 1119 w = POP(); | 1119 w = POP(); |
| 1120 v = TOP(); | 1120 v = TOP(); |
| 1121 if (PyInt_CheckExact(v) && PyInt_CheckExact(w)) { | 1121 if (PyUnicode_CheckExact(v) && |
| 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) && | |
| 1132 PyUnicode_CheckExact(w)) { | 1122 PyUnicode_CheckExact(w)) { |
| 1133 x = unicode_concatenate(v, w, f, next_instr); | 1123 x = unicode_concatenate(v, w, f, next_instr); |
| 1134 /* unicode_concatenate consumed the ref to v */ | 1124 /* unicode_concatenate consumed the ref to v */ |
| 1135 goto skip_decref_vx; | 1125 goto skip_decref_vx; |
| 1136 } | 1126 } |
| 1137 else { | 1127 else { |
| 1138 slow_add: | |
| 1139 x = PyNumber_Add(v, w); | 1128 x = PyNumber_Add(v, w); |
| 1140 } | 1129 } |
| 1141 Py_DECREF(v); | 1130 Py_DECREF(v); |
| 1142 skip_decref_vx: | 1131 skip_decref_vx: |
| 1143 Py_DECREF(w); | 1132 Py_DECREF(w); |
| 1146 break; | 1135 break; |
| 1147 | 1136 |
| 1148 case BINARY_SUBTRACT: | 1137 case BINARY_SUBTRACT: |
| 1149 w = POP(); | 1138 w = POP(); |
| 1150 v = TOP(); | 1139 v = TOP(); |
| 1151 if (PyInt_CheckExact(v) && PyInt_CheckExact(w)) { | 1140 x = PyNumber_Subtract(v, 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 } | |
| 1165 Py_DECREF(v); | 1141 Py_DECREF(v); |
| 1166 Py_DECREF(w); | 1142 Py_DECREF(w); |
| 1167 SET_TOP(x); | 1143 SET_TOP(x); |
| 1168 if (x != NULL) continue; | 1144 if (x != NULL) continue; |
| 1169 break; | 1145 break; |
| 1170 | 1146 |
| 1171 case BINARY_SUBSCR: | 1147 case BINARY_SUBSCR: |
| 1172 w = POP(); | 1148 w = POP(); |
| 1173 v = TOP(); | 1149 v = TOP(); |
| 1174 if (PyList_CheckExact(v) && PyInt_CheckExact(w)) { | 1150 x = PyObject_GetItem(v, 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); | |
| 1189 Py_DECREF(v); | 1151 Py_DECREF(v); |
| 1190 Py_DECREF(w); | 1152 Py_DECREF(w); |
| 1191 SET_TOP(x); | 1153 SET_TOP(x); |
| 1192 if (x != NULL) continue; | 1154 if (x != NULL) continue; |
| 1193 break; | 1155 break; |
| 1317 break; | 1279 break; |
| 1318 | 1280 |
| 1319 case INPLACE_ADD: | 1281 case INPLACE_ADD: |
| 1320 w = POP(); | 1282 w = POP(); |
| 1321 v = TOP(); | 1283 v = TOP(); |
| 1322 if (PyInt_CheckExact(v) && PyInt_CheckExact(w)) { | 1284 if (PyUnicode_CheckExact(v) && |
| 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) && | |
| 1333 PyUnicode_CheckExact(w)) { | 1285 PyUnicode_CheckExact(w)) { |
| 1334 x = unicode_concatenate(v, w, f, next_instr); | 1286 x = unicode_concatenate(v, w, f, next_instr); |
| 1335 /* unicode_concatenate consumed the ref to v */ | 1287 /* unicode_concatenate consumed the ref to v */ |
| 1336 goto skip_decref_v; | 1288 goto skip_decref_v; |
| 1337 } | 1289 } |
| 1338 else { | 1290 else { |
| 1339 slow_iadd: | |
| 1340 x = PyNumber_InPlaceAdd(v, w); | 1291 x = PyNumber_InPlaceAdd(v, w); |
| 1341 } | 1292 } |
| 1342 Py_DECREF(v); | 1293 Py_DECREF(v); |
| 1343 skip_decref_v: | 1294 skip_decref_v: |
| 1344 Py_DECREF(w); | 1295 Py_DECREF(w); |
| 1347 break; | 1298 break; |
| 1348 | 1299 |
| 1349 case INPLACE_SUBTRACT: | 1300 case INPLACE_SUBTRACT: |
| 1350 w = POP(); | 1301 w = POP(); |
| 1351 v = TOP(); | 1302 v = TOP(); |
| 1352 if (PyInt_CheckExact(v) && PyInt_CheckExact(w)) { | 1303 x = PyNumber_InPlaceSubtract(v, 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 } | |
| 1366 Py_DECREF(v); | 1304 Py_DECREF(v); |
| 1367 Py_DECREF(w); | 1305 Py_DECREF(w); |
| 1368 SET_TOP(x); | 1306 SET_TOP(x); |
| 1369 if (x != NULL) continue; | 1307 if (x != NULL) continue; |
| 1370 break; | 1308 break; |
| 1863 break; | 1801 break; |
| 1864 | 1802 |
| 1865 case COMPARE_OP: | 1803 case COMPARE_OP: |
| 1866 w = POP(); | 1804 w = POP(); |
| 1867 v = TOP(); | 1805 v = TOP(); |
| 1868 if (PyInt_CheckExact(w) && PyInt_CheckExact(v)) { | 1806 x = cmp_outcome(oparg, v, w); |
| 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 } | |
| 1892 Py_DECREF(v); | 1807 Py_DECREF(v); |
| 1893 Py_DECREF(w); | 1808 Py_DECREF(w); |
| 1894 SET_TOP(x); | 1809 SET_TOP(x); |
| 1895 if (x == NULL) break; | 1810 if (x == NULL) break; |
| 1896 PREDICT(JUMP_IF_FALSE); | 1811 PREDICT(JUMP_IF_FALSE); |
