Skip to content

Commit 85e3417

Browse files
animalizelisroach
authored andcommitted
replace inline function is_small_int with a macro version (pythonGH-15710)
1 parent e72d772 commit 85e3417

File tree

2 files changed

+10
-15
lines changed

2 files changed

+10
-15
lines changed
Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,2 @@
11
The ``CHECK_SMALL_INT`` macro used inside :file:`Object/longobject.c` has
2-
been replaced with an explicit ``return`` at each call site, conditioned on
3-
a ``static inline`` function ``is_small_int``.
2+
been replaced with an explicit ``return`` at each call site.

Objects/longobject.c

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -42,11 +42,7 @@ PyObject *_PyLong_One = NULL;
4242
*/
4343
static PyLongObject small_ints[NSMALLNEGINTS + NSMALLPOSINTS];
4444

45-
static inline int
46-
is_small_int(long long ival)
47-
{
48-
return -NSMALLNEGINTS <= ival && ival < NSMALLPOSINTS;
49-
}
45+
#define IS_SMALL_INT(ival) (-NSMALLNEGINTS <= (ival) && (ival) < NSMALLPOSINTS)
5046

5147
#ifdef COUNT_ALLOCS
5248
Py_ssize_t _Py_quick_int_allocs, _Py_quick_neg_int_allocs;
@@ -56,7 +52,7 @@ static PyObject *
5652
get_small_int(sdigit ival)
5753
{
5854
PyObject *v;
59-
assert(is_small_int(ival));
55+
assert(IS_SMALL_INT(ival));
6056
v = (PyObject *)&small_ints[ival + NSMALLNEGINTS];
6157
Py_INCREF(v);
6258
#ifdef COUNT_ALLOCS
@@ -73,16 +69,16 @@ maybe_small_long(PyLongObject *v)
7369
{
7470
if (v && Py_ABS(Py_SIZE(v)) <= 1) {
7571
sdigit ival = MEDIUM_VALUE(v);
76-
if (is_small_int(ival)) {
72+
if (IS_SMALL_INT(ival)) {
7773
Py_DECREF(v);
7874
return (PyLongObject *)get_small_int(ival);
7975
}
8076
}
8177
return v;
8278
}
8379
#else
84-
#define is_small_int(ival) 0
85-
#define get_small_int(ival) (assert(0), NULL)
80+
#define IS_SMALL_INT(ival) 0
81+
#define get_small_int(ival) (Py_UNREACHABLE(), NULL)
8682
#define maybe_small_long(val) (val)
8783
#endif
8884

@@ -297,7 +293,7 @@ _PyLong_Copy(PyLongObject *src)
297293
i = -(i);
298294
if (i < 2) {
299295
sdigit ival = MEDIUM_VALUE(src);
300-
if (is_small_int(ival)) {
296+
if (IS_SMALL_INT(ival)) {
301297
return get_small_int(ival);
302298
}
303299
}
@@ -321,7 +317,7 @@ PyLong_FromLong(long ival)
321317
int ndigits = 0;
322318
int sign;
323319

324-
if (is_small_int(ival)) {
320+
if (IS_SMALL_INT(ival)) {
325321
return get_small_int((sdigit)ival);
326322
}
327323

@@ -1154,7 +1150,7 @@ PyLong_FromLongLong(long long ival)
11541150
int ndigits = 0;
11551151
int negative = 0;
11561152

1157-
if (is_small_int(ival)) {
1153+
if (IS_SMALL_INT(ival)) {
11581154
return get_small_int((sdigit)ival);
11591155
}
11601156

@@ -1229,7 +1225,7 @@ PyLong_FromSsize_t(Py_ssize_t ival)
12291225
int ndigits = 0;
12301226
int negative = 0;
12311227

1232-
if (is_small_int(ival)) {
1228+
if (IS_SMALL_INT(ival)) {
12331229
return get_small_int((sdigit)ival);
12341230
}
12351231

0 commit comments

Comments
 (0)