Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
cpython
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
cpython
Commits
6b519985
Commit
6b519985
authored
Sep 06, 2019
by
animalize
Committed by
Raymond Hettinger
Sep 05, 2019
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
replace inline function `is_small_int` with a macro version (GH-15710)
parent
3f43ceff
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
10 additions
and
15 deletions
+10
-15
Misc/NEWS.d/next/Core and Builtins/2019-08-23-22-46-25.bpo-37812.vsWZwS.rst
...ore and Builtins/2019-08-23-22-46-25.bpo-37812.vsWZwS.rst
+1
-2
Objects/longobject.c
Objects/longobject.c
+9
-13
No files found.
Misc/NEWS.d/next/Core and Builtins/2019-08-23-22-46-25.bpo-37812.vsWZwS.rst
View file @
6b519985
The ``CHECK_SMALL_INT`` macro used inside :file:`Object/longobject.c` has
been replaced with an explicit ``return`` at each call site, conditioned on
a ``static inline`` function ``is_small_int``.
been replaced with an explicit ``return`` at each call site.
Objects/longobject.c
View file @
6b519985
...
...
@@ -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
);
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment