Closed
Description
Currently Integer.__index__()
goes via a python long. In most cases the result should be just a python int, and it should be much faster to go directly there.
Probably the best way to implement this is to first call mpz_size(x.value)
to check the size in words; if the size is one, then construct a python int directly; otherwise go to a long.
Even better might be to write another version of mpz_get_pylong
which can produce a python int when that's feasible, or a long if it's not.
Component: basic arithmetic
Issue created by migration from https://trac.sagemath.org/ticket/440