Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
cpython
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
cpython
Commits
d9c116ca
Commit
d9c116ca
authored
Jul 09, 2013
by
Raymond Hettinger
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add a spacing saving heuristic to deque's extend methods
parent
bbf8ce5b
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
18 additions
and
2 deletions
+18
-2
Lib/test/test_deque.py
Lib/test/test_deque.py
+2
-2
Modules/_collectionsmodule.c
Modules/_collectionsmodule.c
+16
-0
No files found.
Lib/test/test_deque.py
View file @
d9c116ca
...
...
@@ -543,8 +543,8 @@ class TestBasic(unittest.TestCase):
check
=
self
.
check_sizeof
check
(
deque
(),
basesize
+
blocksize
)
check
(
deque
(
'a'
),
basesize
+
blocksize
)
check
(
deque
(
'a'
*
(
BLOCKLEN
//
2
)),
basesize
+
blocksize
)
check
(
deque
(
'a'
*
(
BLOCKLEN
//
2
+
1
)
),
basesize
+
2
*
blocksize
)
check
(
deque
(
'a'
*
(
BLOCKLEN
-
1
)),
basesize
+
blocksize
)
check
(
deque
(
'a'
*
BLOCKLEN
),
basesize
+
2
*
blocksize
)
check
(
deque
(
'a'
*
(
42
*
BLOCKLEN
)),
basesize
+
43
*
blocksize
)
class
TestVariousIteratorArgs
(
unittest
.
TestCase
):
...
...
Modules/_collectionsmodule.c
View file @
d9c116ca
...
...
@@ -332,6 +332,14 @@ deque_extend(dequeobject *deque, PyObject *iterable)
return
result
;
}
/* Space saving heuristic. Start filling from the left */
if
(
Py_SIZE
(
deque
)
==
0
)
{
assert
(
deque
->
leftblock
==
deque
->
rightblock
);
assert
(
deque
->
leftindex
==
deque
->
rightindex
+
1
);
deque
->
leftindex
=
1
;
deque
->
rightindex
=
0
;
}
it
=
PyObject_GetIter
(
iterable
);
if
(
it
==
NULL
)
return
NULL
;
...
...
@@ -385,6 +393,14 @@ deque_extendleft(dequeobject *deque, PyObject *iterable)
return
result
;
}
/* Space saving heuristic. Start filling from the right */
if
(
Py_SIZE
(
deque
)
==
0
)
{
assert
(
deque
->
leftblock
==
deque
->
rightblock
);
assert
(
deque
->
leftindex
==
deque
->
rightindex
+
1
);
deque
->
leftindex
=
BLOCKLEN
-
1
;
deque
->
rightindex
=
BLOCKLEN
-
2
;
}
it
=
PyObject_GetIter
(
iterable
);
if
(
it
==
NULL
)
return
NULL
;
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment