mirror of
https://github.com/python/cpython.git
synced 2025-11-13 07:26:31 +00:00
Minor performance tweak for deque.index() with a start argument (GH-9440)
This commit is contained in:
parent
fb3e9c00ed
commit
b46ad5431d
2 changed files with 12 additions and 2 deletions
|
|
@ -288,6 +288,14 @@ class TestBasic(unittest.TestCase):
|
||||||
else:
|
else:
|
||||||
self.assertEqual(d.index(element, start, stop), target)
|
self.assertEqual(d.index(element, start, stop), target)
|
||||||
|
|
||||||
|
# Test large start argument
|
||||||
|
d = deque(range(0, 10000, 10))
|
||||||
|
for step in range(100):
|
||||||
|
i = d.index(8500, 700)
|
||||||
|
self.assertEqual(d[i], 8500)
|
||||||
|
# Repeat test with a different internal offset
|
||||||
|
d.rotate()
|
||||||
|
|
||||||
def test_index_bug_24913(self):
|
def test_index_bug_24913(self):
|
||||||
d = deque('A' * 3)
|
d = deque('A' * 3)
|
||||||
with self.assertRaises(ValueError):
|
with self.assertRaises(ValueError):
|
||||||
|
|
|
||||||
|
|
@ -1050,8 +1050,10 @@ deque_index(dequeobject *deque, PyObject *const *args, Py_ssize_t nargs)
|
||||||
start = stop;
|
start = stop;
|
||||||
assert(0 <= start && start <= stop && stop <= Py_SIZE(deque));
|
assert(0 <= start && start <= stop && stop <= Py_SIZE(deque));
|
||||||
|
|
||||||
/* XXX Replace this loop with faster code from deque_item() */
|
for (i=0 ; i < start - BLOCKLEN ; i += BLOCKLEN) {
|
||||||
for (i=0 ; i<start ; i++) {
|
b = b->rightlink;
|
||||||
|
}
|
||||||
|
for ( ; i < start ; i++) {
|
||||||
index++;
|
index++;
|
||||||
if (index == BLOCKLEN) {
|
if (index == BLOCKLEN) {
|
||||||
b = b->rightlink;
|
b = b->rightlink;
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue