diff options
author | Raymond Hettinger <python@rcn.com> | 2015-03-24 06:23:55 (GMT) |
---|---|---|
committer | Raymond Hettinger <python@rcn.com> | 2015-03-24 06:23:55 (GMT) |
commit | 0f1451c8c06ce275c0dfe3a08b024b29967840bc (patch) | |
tree | 929b8f756b06b89a574649b772cce189a24ec91a /Modules/_collectionsmodule.c | |
parent | 929a14a880c6b021346ed827d901b197d3afae44 (diff) | |
download | cpython-0f1451c8c06ce275c0dfe3a08b024b29967840bc.zip cpython-0f1451c8c06ce275c0dfe3a08b024b29967840bc.tar.gz cpython-0f1451c8c06ce275c0dfe3a08b024b29967840bc.tar.bz2 |
Issue 23744: Minor speed-up for deque.__bool__().
Diffstat (limited to 'Modules/_collectionsmodule.c')
-rw-r--r-- | Modules/_collectionsmodule.c | 25 |
1 files changed, 24 insertions, 1 deletions
diff --git a/Modules/_collectionsmodule.c b/Modules/_collectionsmodule.c index b831627..dc8e698 100644 --- a/Modules/_collectionsmodule.c +++ b/Modules/_collectionsmodule.c @@ -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 */ |