Issue 23744: Minor speed-up for deque.__bool__().

This commit is contained in:
Raymond Hettinger 2015-03-23 23:23:55 -07:00
parent 929a14a880
commit 0f1451c8c0
1 changed files with 24 additions and 1 deletions

View File

@ -1249,6 +1249,12 @@ deque_sizeof(dequeobject *deque, void *unused)
PyDoc_STRVAR(sizeof_doc,
"D.__sizeof__() -- size of D in memory, in bytes");
static int
deque_bool(dequeobject *deque)
{
return Py_SIZE(deque) != 0;
}
static PyObject *
deque_get_maxlen(dequeobject *deque)
{
@ -1276,6 +1282,23 @@ static PySequenceMethods deque_as_sequence = {
0, /* sq_inplace_repeat */
};
static PyNumberMethods deque_as_number = {
0, /* nb_add */
0, /* nb_subtract */
0, /* nb_multiply */
0, /* nb_remainder */
0, /* nb_divmod */
0, /* nb_power */
0, /* nb_negative */
0, /* nb_positive */
0, /* nb_absolute */
(inquiry)deque_bool, /* nb_bool */
0, /* nb_invert */
0, /* nb_lshift */
0, /* nb_rshift */
};
/* deque object ********************************************************/
static PyObject *deque_iter(dequeobject *deque);
@ -1340,7 +1363,7 @@ static PyTypeObject deque_type = {
0, /* tp_setattr */
0, /* tp_reserved */
deque_repr, /* tp_repr */
0, /* tp_as_number */
&deque_as_number, /* tp_as_number */
&deque_as_sequence, /* tp_as_sequence */
0, /* tp_as_mapping */
PyObject_HashNotImplemented, /* tp_hash */