-
-
Notifications
You must be signed in to change notification settings - Fork 34.4k
Expand file tree
/
Copy pathpycore_range.h
More file actions
60 lines (53 loc) · 1.39 KB
/
pycore_range.h
File metadata and controls
60 lines (53 loc) · 1.39 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
#ifndef Py_INTERNAL_RANGE_H
#define Py_INTERNAL_RANGE_H
#ifdef __cplusplus
extern "C" {
#endif
#ifndef Py_BUILD_CORE
# error "this header requires Py_BUILD_CORE define"
#endif
typedef struct {
PyObject_HEAD
PyObject *start;
PyObject *stop;
PyObject *step;
PyObject *length;
} rangeobject;
typedef struct {
PyObject_HEAD
long start;
long step;
long len;
} _PyRangeIterObject;
// Does this range have step == 1 and both start and stop in compact int range?
static inline int
_PyRange_IsSimpleCompact(PyObject *range) {
assert(PyRange_Check(range));
rangeobject *r = (rangeobject*)range;
if (_PyLong_IsCompact((PyLongObject *)r->start) &&
_PyLong_IsCompact((PyLongObject *)r->stop) &&
r->step == _PyLong_GetOne()
) {
return 1;
}
return 0;
}
static inline Py_ssize_t
_PyRange_GetStartIfCompact(PyObject *range)
{
assert(PyRange_Check(range));
rangeobject *r = (rangeobject*)range;
assert(_PyLong_IsCompact((PyLongObject *)r->start));
return _PyLong_CompactValue((PyLongObject *)r->start);
}
static inline Py_ssize_t
_PyRange_GetStopIfCompact(PyObject *range) {
assert(PyRange_Check(range));
rangeobject *r = (rangeobject*)range;
assert(_PyLong_IsCompact((PyLongObject *)r->stop));
return _PyLong_CompactValue((PyLongObject *)r->stop);
}
#ifdef __cplusplus
}
#endif
#endif /* !Py_INTERNAL_RANGE_H */