This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author vstinner
Recipients corona10, pablogsal, serhiy.storchaka, vstinner
Date 2020-10-01.14:55:34
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1601564135.0.0.359677849173.issue41902@roundup.psfhosted.org>
In-reply-to
Content
PR 22479 avoids calling PyNumber_FloorDivide(a, b) if b == 1 (if b == _PyLong_One): it makes range.index(a, 1) call 214 ns faster. I'm surprised that PyNumber_FloorDivide(a, 1) takes 214 ns. Does it spend most time in binary_op1()? Or PyNumber_FloorDivide()?

long_div(a, 1) is quite simple:

    CHECK_BINOP(a, b);

    if (Py_ABS(Py_SIZE(a)) == 1 && Py_ABS(Py_SIZE(b)) == 1) {
        return fast_floor_div((PyLongObject*)a, (PyLongObject*)b);

with:

static PyObject *
fast_floor_div(PyLongObject *a, PyLongObject *b)
{
    sdigit left = a->ob_digit[0];
    sdigit right = b->ob_digit[0];
    sdigit div;
    if (Py_SIZE(a) == Py_SIZE(b)) {
        div = left / right;
    }
    else {
        div = -1 - (left - 1) / right;
    }
    return PyLong_FromLong(div);
}

Do we need another fast-path in long_div(a, b) when b == _PyLong_One? Just return a in this case.
History
Date User Action Args
2020-10-01 14:55:35vstinnersetrecipients: + vstinner, serhiy.storchaka, corona10, pablogsal
2020-10-01 14:55:34vstinnersetmessageid: <1601564135.0.0.359677849173.issue41902@roundup.psfhosted.org>
2020-10-01 14:55:34vstinnerlinkissue41902 messages
2020-10-01 14:55:34vstinnercreate