Skip to content

Commit e5f666d

Browse files
committed
Make functions inline for the JIT
1 parent 7325b44 commit e5f666d

File tree

2 files changed

+37
-46
lines changed

2 files changed

+37
-46
lines changed

Include/internal/pycore_range.h

Lines changed: 37 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,14 @@ extern "C" {
88
# error "this header requires Py_BUILD_CORE define"
99
#endif
1010

11+
typedef struct {
12+
PyObject_HEAD
13+
PyObject *start;
14+
PyObject *stop;
15+
PyObject *step;
16+
PyObject *length;
17+
} rangeobject;
18+
1119
typedef struct {
1220
PyObject_HEAD
1321
long start;
@@ -16,9 +24,35 @@ typedef struct {
1624
} _PyRangeIterObject;
1725

1826
// Does this range have step == 1 and both start and stop in compact int range?
19-
int _PyRange_IsSimpleCompact(PyObject *range);
20-
Py_ssize_t _PyRange_GetStartIfCompact(PyObject *range);
21-
Py_ssize_t _PyRange_GetStopIfCompact(PyObject *range);
27+
static inline int
28+
_PyRange_IsSimpleCompact(PyObject *range) {
29+
assert(PyRange_Check(range));
30+
rangeobject *r = (rangeobject*)range;
31+
if (_PyLong_IsCompact((PyLongObject *)r->start) &&
32+
_PyLong_IsCompact((PyLongObject *)r->stop) &&
33+
r->step == _PyLong_GetOne()
34+
) {
35+
return 1;
36+
}
37+
return 0;
38+
}
39+
40+
static inline Py_ssize_t
41+
_PyRange_GetStartIfCompact(PyObject *range)
42+
{
43+
assert(PyRange_Check(range));
44+
rangeobject *r = (rangeobject*)range;
45+
assert(_PyLong_IsCompact((PyLongObject *)r->start));
46+
return _PyLong_CompactValue((PyLongObject *)r->start);
47+
}
48+
49+
static inline Py_ssize_t
50+
_PyRange_GetStopIfCompact(PyObject *range) {
51+
assert(PyRange_Check(range));
52+
rangeobject *r = (rangeobject*)range;
53+
assert(_PyLong_IsCompact((PyLongObject *)r->stop));
54+
return _PyLong_CompactValue((PyLongObject *)r->stop);
55+
}
2256

2357
#ifdef __cplusplus
2458
}

Objects/rangeobject.c

Lines changed: 0 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -10,21 +10,6 @@
1010
#include "pycore_tuple.h" // _PyTuple_ITEMS()
1111

1212

13-
/* Support objects whose length is > PY_SSIZE_T_MAX.
14-
15-
This could be sped up for small PyLongs if they fit in a Py_ssize_t.
16-
This only matters on Win64. Though we could use long long which
17-
would presumably help perf.
18-
*/
19-
20-
typedef struct {
21-
PyObject_HEAD
22-
PyObject *start;
23-
PyObject *stop;
24-
PyObject *step;
25-
PyObject *length;
26-
} rangeobject;
27-
2813
/* Helper function for validating step. Always returns a new reference or
2914
NULL on error.
3015
*/
@@ -156,34 +141,6 @@ range_vectorcall(PyObject *rangetype, PyObject *const *args,
156141
return range_from_array((PyTypeObject *)rangetype, args, nargs);
157142
}
158143

159-
int
160-
_PyRange_IsSimpleCompact(PyObject *range) {
161-
assert(PyRange_Check(range));
162-
rangeobject *r = (rangeobject*)range;
163-
if (_PyLong_IsCompact((PyLongObject *)r->start) &&
164-
_PyLong_IsCompact((PyLongObject *)r->stop) &&
165-
r->step == _PyLong_GetOne()
166-
) {
167-
return 1;
168-
}
169-
return 0;
170-
}
171-
172-
Py_ssize_t
173-
_PyRange_GetStartIfCompact(PyObject *range) {
174-
assert(PyRange_Check(range));
175-
rangeobject *r = (rangeobject*)range;
176-
assert(_PyLong_IsCompact((PyLongObject *)r->start));
177-
return _PyLong_CompactValue((PyLongObject *)r->start);
178-
}
179-
180-
Py_ssize_t
181-
_PyRange_GetStopIfCompact(PyObject *range) {
182-
assert(PyRange_Check(range));
183-
rangeobject *r = (rangeobject*)range;
184-
assert(_PyLong_IsCompact((PyLongObject *)r->stop));
185-
return _PyLong_CompactValue((PyLongObject *)r->stop);
186-
}
187144

188145
PyDoc_STRVAR(range_doc,
189146
"range(stop) -> range object\n\

0 commit comments

Comments
 (0)