summaryrefslogtreecommitdiffstats
path: root/Objects
diff options
context:
space:
mode:
authoranimalize <animalize@users.noreply.github.com>2019-09-06 06:00:56 (GMT)
committerRaymond Hettinger <rhettinger@users.noreply.github.com>2019-09-06 06:00:56 (GMT)
commit6b519985d23bd0f0bd072b5d5d5f2c60a81a19f2 (patch)
treee0d74dc749c4664dbcf80273d29e9fee7c4291dc /Objects
parent3f43ceff186da09978d0aff257bb18b8ac7611f7 (diff)
downloadcpython-6b519985d23bd0f0bd072b5d5d5f2c60a81a19f2.zip
cpython-6b519985d23bd0f0bd072b5d5d5f2c60a81a19f2.tar.gz
cpython-6b519985d23bd0f0bd072b5d5d5f2c60a81a19f2.tar.bz2
replace inline function `is_small_int` with a macro version (GH-15710)
Diffstat (limited to 'Objects')
-rw-r--r--Objects/longobject.c22
1 files changed, 9 insertions, 13 deletions
diff --git a/Objects/longobject.c b/Objects/longobject.c
index 475b9bd..4cf2b07 100644
--- a/Objects/longobject.c
+++ b/Objects/longobject.c
@@ -42,11 +42,7 @@ PyObject *_PyLong_One = NULL;
*/
static PyLongObject small_ints[NSMALLNEGINTS + NSMALLPOSINTS];
-static inline int
-is_small_int(long long ival)
-{
- return -NSMALLNEGINTS <= ival && ival < NSMALLPOSINTS;
-}
+#define IS_SMALL_INT(ival) (-NSMALLNEGINTS <= (ival) && (ival) < NSMALLPOSINTS)
#ifdef COUNT_ALLOCS
Py_ssize_t _Py_quick_int_allocs, _Py_quick_neg_int_allocs;
@@ -56,7 +52,7 @@ static PyObject *
get_small_int(sdigit ival)
{
PyObject *v;
- assert(is_small_int(ival));
+ assert(IS_SMALL_INT(ival));
v = (PyObject *)&small_ints[ival + NSMALLNEGINTS];
Py_INCREF(v);
#ifdef COUNT_ALLOCS
@@ -73,7 +69,7 @@ maybe_small_long(PyLongObject *v)
{
if (v && Py_ABS(Py_SIZE(v)) <= 1) {
sdigit ival = MEDIUM_VALUE(v);
- if (is_small_int(ival)) {
+ if (IS_SMALL_INT(ival)) {
Py_DECREF(v);
return (PyLongObject *)get_small_int(ival);
}
@@ -81,8 +77,8 @@ maybe_small_long(PyLongObject *v)
return v;
}
#else
-#define is_small_int(ival) 0
-#define get_small_int(ival) (assert(0), NULL)
+#define IS_SMALL_INT(ival) 0
+#define get_small_int(ival) (Py_UNREACHABLE(), NULL)
#define maybe_small_long(val) (val)
#endif
@@ -297,7 +293,7 @@ _PyLong_Copy(PyLongObject *src)
i = -(i);
if (i < 2) {
sdigit ival = MEDIUM_VALUE(src);
- if (is_small_int(ival)) {
+ if (IS_SMALL_INT(ival)) {
return get_small_int(ival);
}
}
@@ -321,7 +317,7 @@ PyLong_FromLong(long ival)
int ndigits = 0;
int sign;
- if (is_small_int(ival)) {
+ if (IS_SMALL_INT(ival)) {
return get_small_int((sdigit)ival);
}
@@ -1154,7 +1150,7 @@ PyLong_FromLongLong(long long ival)
int ndigits = 0;
int negative = 0;
- if (is_small_int(ival)) {
+ if (IS_SMALL_INT(ival)) {
return get_small_int((sdigit)ival);
}
@@ -1229,7 +1225,7 @@ PyLong_FromSsize_t(Py_ssize_t ival)
int ndigits = 0;
int negative = 0;
- if (is_small_int(ival)) {
+ if (IS_SMALL_INT(ival)) {
return get_small_int((sdigit)ival);
}