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
2cdb6435
Commit
2cdb6435
authored
Jan 12, 2013
by
Raymond Hettinger
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Issue #16398: Optimize deque.rotate()
parent
92e2fc83
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
61 additions
and
14 deletions
+61
-14
Misc/NEWS
Misc/NEWS
+3
-0
Modules/_collectionsmodule.c
Modules/_collectionsmodule.c
+58
-14
No files found.
Misc/NEWS
View file @
2cdb6435
...
...
@@ -189,6 +189,9 @@ Library
-
Issue
#
13899
:
\
A
,
\
Z
,
and
\
B
now
correctly
match
the
A
,
Z
,
and
B
literals
when
used
inside
character
classes
(
e
.
g
.
'[\A]'
).
Patch
by
Matthew
Barnett
.
-
Issue
#
16398
:
Optimize
deque
.
rotate
()
so
that
it
only
moves
pointers
and
doesn
't touch the underlying data with increfs and decrefs.
- Issue #15109: Fix regression in sqlite3'
s
iterdump
method
where
it
would
die
with
an
encoding
error
if
the
database
contained
string
values
containing
non
-
ASCII
.
(
Regression
was
introduced
by
fix
for
9750
).
...
...
Modules/_collectionsmodule.c
View file @
2cdb6435
...
...
@@ -414,9 +414,10 @@ static int
_deque_rotate
(
dequeobject
*
deque
,
Py_ssize_t
n
)
{
Py_ssize_t
i
,
len
=
deque
->
len
,
halflen
=
(
len
+
1
)
>>
1
;
PyObject
*
item
,
*
rv
;
PyObject
*
item
;
block
*
prevblock
,
*
leftblock
,
*
rightblock
;
if
(
len
==
0
)
if
(
len
<=
1
)
return
0
;
if
(
n
>
halflen
||
n
<
-
halflen
)
{
n
%=
len
;
...
...
@@ -426,23 +427,66 @@ _deque_rotate(dequeobject *deque, Py_ssize_t n)
n
+=
len
;
}
assert
(
deque
->
len
>
1
);
deque
->
state
++
;
leftblock
=
deque
->
leftblock
;
rightblock
=
deque
->
rightblock
;
for
(
i
=
0
;
i
<
n
;
i
++
)
{
item
=
deque_pop
(
deque
,
NULL
)
;
item
=
rightblock
->
data
[
deque
->
rightindex
]
;
assert
(
item
!=
NULL
);
rv
=
deque_appendleft
(
deque
,
item
);
Py_DECREF
(
item
);
if
(
rv
==
NULL
)
return
-
1
;
Py_DECREF
(
rv
);
deque
->
rightindex
--
;
if
(
deque
->
rightindex
==
-
1
)
{
assert
(
rightblock
!=
NULL
);
prevblock
=
rightblock
->
leftlink
;
assert
(
leftblock
!=
rightblock
);
freeblock
(
rightblock
);
prevblock
->
rightlink
=
NULL
;
deque
->
rightblock
=
rightblock
=
prevblock
;
deque
->
rightindex
=
BLOCKLEN
-
1
;
}
if
(
deque
->
leftindex
==
0
)
{
block
*
b
=
newblock
(
NULL
,
leftblock
,
deque
->
len
);
if
(
b
==
NULL
)
{
deque
->
len
--
;
Py_DECREF
(
item
);
return
-
1
;
}
assert
(
leftblock
->
leftlink
==
NULL
);
leftblock
->
leftlink
=
b
;
deque
->
leftblock
=
leftblock
=
b
;
deque
->
leftindex
=
BLOCKLEN
;
}
deque
->
leftindex
--
;
leftblock
->
data
[
deque
->
leftindex
]
=
item
;
}
for
(
i
=
0
;
i
>
n
;
i
--
)
{
item
=
deque_popleft
(
deque
,
NULL
);
assert
(
leftblock
!=
NULL
);
item
=
leftblock
->
data
[
deque
->
leftindex
];
assert
(
item
!=
NULL
);
rv
=
deque_append
(
deque
,
item
);
Py_DECREF
(
item
);
if
(
rv
==
NULL
)
return
-
1
;
Py_DECREF
(
rv
);
deque
->
leftindex
++
;
if
(
deque
->
leftindex
==
BLOCKLEN
)
{
assert
(
leftblock
!=
rightblock
);
prevblock
=
leftblock
->
rightlink
;
freeblock
(
leftblock
);
assert
(
prevblock
!=
NULL
);
prevblock
->
leftlink
=
NULL
;
deque
->
leftblock
=
leftblock
=
prevblock
;
deque
->
leftindex
=
0
;
}
if
(
deque
->
rightindex
==
BLOCKLEN
-
1
)
{
block
*
b
=
newblock
(
rightblock
,
NULL
,
deque
->
len
);
if
(
b
==
NULL
)
{
deque
->
len
--
;
Py_DECREF
(
item
);
return
-
1
;
}
assert
(
rightblock
->
rightlink
==
NULL
);
rightblock
->
rightlink
=
b
;
deque
->
rightblock
=
rightblock
=
b
;
deque
->
rightindex
=
-
1
;
}
deque
->
rightindex
++
;
rightblock
->
data
[
deque
->
rightindex
]
=
item
;
}
return
0
;
}
...
...
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