Skip to content

Commit 53a4e24

Browse files
committed
Don't handle the shift==0 special-case until we need to
1 parent 27843b1 commit 53a4e24

File tree

1 file changed

+6
-11
lines changed

1 file changed

+6
-11
lines changed

Objects/longobject.c

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4487,7 +4487,7 @@ divmod_shift(PyObject *shiftby, Py_ssize_t *wordshift, digit *remshift)
44874487
}
44884488

44894489
/* Inner function for both long_rshift and _PyLong_Rshift, shifting an
4490-
integer right by a strictly positive shift. */
4490+
integer right by a nonnegative shift. */
44914491

44924492
static PyObject *
44934493
long_rshift1(PyLongObject *a, Py_ssize_t wordshift, digit remshift)
@@ -4497,8 +4497,6 @@ long_rshift1(PyLongObject *a, Py_ssize_t wordshift, digit remshift)
44974497
twodigits accum;
44984498
int a_negative;
44994499

4500-
assert (wordshift > 0 || remshift > 0);
4501-
45024500
/* Fast path for small a. */
45034501
if (IS_MEDIUM_VALUE(a)) {
45044502
stwodigits m, x;
@@ -4518,10 +4516,14 @@ long_rshift1(PyLongObject *a, Py_ssize_t wordshift, digit remshift)
45184516
if (remshift == 0) {
45194517
remshift = PyLong_SHIFT;
45204518
--wordshift;
4519+
if (wordshift < 0) {
4520+
/* Can only happen if the original shift was 0. */
4521+
return long_long(a);
4522+
}
45214523
}
4522-
assert(wordshift >= 0);
45234524
}
45244525

4526+
assert(wordshift >= 0);
45254527
newsize = size_a - wordshift;
45264528
if (newsize <= 0) {
45274529
return PyLong_FromLong(-a_negative);
@@ -4584,9 +4586,6 @@ long_rshift(PyObject *a, PyObject *b)
45844586
PyErr_SetString(PyExc_ValueError, "negative shift count");
45854587
return NULL;
45864588
}
4587-
if (Py_SIZE(b) == 0) {
4588-
return long_long(a);
4589-
}
45904589
if (Py_SIZE(a) == 0) {
45914590
return PyLong_FromLong(0);
45924591
}
@@ -4603,10 +4602,6 @@ _PyLong_Rshift(PyObject *a, size_t shiftby)
46034602
digit remshift;
46044603

46054604
assert(PyLong_Check(a));
4606-
4607-
if (shiftby == 0) {
4608-
return long_long(a);
4609-
}
46104605
if (Py_SIZE(a) == 0) {
46114606
return PyLong_FromLong(0);
46124607
}

0 commit comments

Comments
 (0)