I(0) << whatever, I(0) >> whatever, I(whatever) << 0 and I(whatever) >> 0
optimizations.
a = hexint(12345)
verify(int(a) == 12345)
verify(int(a).__class__ is int)
+ verify((+a).__class__ is int)
+ verify((a >> 0).__class__ is int)
+ verify((a << 0).__class__ is int)
+ verify((hexint(0) << 12).__class__ is int)
+ verify((hexint(0) >> 12).__class__ is int)
class octlong(long):
__slots__ = []
static PyObject *
int_pos(PyIntObject *v)
{
- Py_INCREF(v);
- return (PyObject *)v;
+ if (PyInt_CheckExact(v)) {
+ Py_INCREF(v);
+ return (PyObject *)v;
+ }
+ else
+ return PyInt_FromLong(v->ob_ival);
}
static PyObject *
PyErr_SetString(PyExc_ValueError, "negative shift count");
return NULL;
}
- if (a == 0 || b == 0) {
- Py_INCREF(v);
- return (PyObject *) v;
- }
+ if (a == 0 || b == 0)
+ return int_pos(v);
if (b >= LONG_BIT) {
return PyInt_FromLong(0L);
}
PyErr_SetString(PyExc_ValueError, "negative shift count");
return NULL;
}
- if (a == 0 || b == 0) {
- Py_INCREF(v);
- return (PyObject *) v;
- }
+ if (a == 0 || b == 0)
+ return int_pos(v);
if (b >= LONG_BIT) {
if (a < 0)
a = -1;