8000 bpo-44946: Streamline operators and creation of ints for common case of single 'digit'. by markshannon · Pull Request #27832 · python/cpython · GitHub
[go: up one dir, main page]

Skip to content

bpo-44946: Streamline operators and creation of ints for common case of single 'digit'. #27832

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 17 commits into from
Aug 25, 2021
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Reduce the number of casts.
  • Loading branch information
markshannon committed Aug 19, 2021
commit 5e4aad51ed94127100029d032d866445e0057037
10 changes: 5 additions & 5 deletions Objects/longobject.c
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,14 @@ _Py_IDENTIFIER(little);
_Py_IDENTIFIER(big);

/* Is this PyLong of size 1, 0 or -1? */
#define IS_MEDIUM_VALUE(x) (((size_t)Py_SIZE(x)) + 1 < 3)
#define IS_MEDIUM_VALUE(x) (((size_t)Py_SIZE(x)) + 1U < 3U)

/* convert a PyLong of size 1, 0 or -1 to a C integer */
static inline sdigit
static inline stwodigits
medium_value(PyLongObject *x)
{
assert(IS_MEDIUM_VALUE(x));
return Py_SIZE(x) * x->ob_digit[0];
return ((stwodigits)Py_SIZE(x)) * x->ob_digit[0];
}

#define IS_SMALL_INT(ival) (-NSMALLNEGINTS <= (ival) && (ival) < NSMALLPOSINTS)
Expand All @@ -55,7 +55,7 @@ static PyLongObject *
maybe_small_long(PyLongObject *v)
{
if (v & 8000 ;& IS_MEDIUM_VALUE(v)) {
long ival = medium_value(v);
sdigit ival = medium_value(v);
if (IS_SMALL_INT(ival)) {
Py_DECREF(v);
return (PyLongObject *)get_small_int(ival);
Expand Down Expand Up @@ -3565,7 +3565,7 @@ long_mul(PyLongObject *a, PyLongObject *b)

/* fast path for single-digit multiplication */
if (IS_MEDIUM_VALUE(a) && IS_MEDIUM_VALUE(b)) {
stwodigits v = (stwodigits)(medium_value(a)) * medium_value(b);
stwodigits v = medium_value(a) * medium_value(b);
return PyLong_FromLongLong((long long)v);
}

Expand Down
0