Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
cython
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
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Boxiang Sun
cython
Commits
72cb404f
Commit
72cb404f
authored
7 years ago
by
Stefan Behnel
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Optimise list.extend([...]) into list.extend((...)) since tuples are more efficient than lists.
parent
67b3ef81
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
7 additions
and
3 deletions
+7
-3
Cython/Compiler/Optimize.py
Cython/Compiler/Optimize.py
+7
-3
No files found.
Cython/Compiler/Optimize.py
View file @
72cb404f
...
...
@@ -2829,12 +2829,16 @@ class OptimizeBuiltinCalls(Visitor.NodeRefCleanupMixin,
if
len
(
args
)
!=
2
:
return
node
obj
,
value
=
args
if
not
value
.
is_sequence_constructor
or
value
.
mult_factor
is
not
None
:
if
not
value
.
is_sequence_constructor
:
return
node
items
=
list
(
value
.
args
)
if
len
(
items
)
>
4
:
# Appending wins for short sequences.
if
value
.
mult_factor
is
not
None
or
len
(
items
)
>
4
:
# Appending wins for short sequences
but might slow down for multiple resize operations
.
# Ignorantly assume that this a good enough limit that avoids repeated resizing.
if
isinstance
(
value
,
ExprNodes
.
ListNode
):
# At least avoid the list building and use a faster tuple instead.
tuple_node
=
args
[
1
].
as_tuple
().
analyse_types
(
self
.
current_env
(),
skip_children
=
True
)
Visitor
.
recursively_replace_node
(
node
,
args
[
1
],
tuple_node
)
return
node
wrapped_obj
=
self
.
_wrap_self_arg
(
obj
,
function
,
is_unbound_method
,
'extend'
)
if
not
items
:
...
...
This diff is collapsed.
Click to expand it.
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