[issue23744] Speed-up deque.__bool__

Josh Rosenberg report at bugs.python.org
Tue Mar 24 03:06:23 CET 2015


Josh Rosenberg added the comment:

On further checking, this probably gives slightly greater benefit to deque than it would for list, tuple, dict, etc., only because PyObject_IsTrue checks for mapping before sequence; deque is a pure sequence, no mapping, so it has to fail an extra test before it reaches the sequence length interface check and uses it, where any sequence that supports extended slicing must support parts of the mapping interface, and usually copies the sequence function pointer to the mapping length slot as well.

Still hard to justify, though. Testing the truthiness of a deque is not likely to be the critical code path for many applications (if you want to take advantage of deque's atomic behaviors, you're using EAFP patterns anyway, not testing truthiness), and the gain in boolean testing means other (likely low probability tests) will run slower (for example, testing a deque with PyNumber_Check would go slower, because it would pass an extra test before failing each time).

----------

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue23744>
_______________________________________


More information about the Python-bugs-list mailing list