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
Labels
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Commits
Open sidebar
nexedi
cython
Commits
3f75d910
Commit
3f75d910
authored
Apr 06, 2015
by
Stefan Behnel
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
optimise **kwargs copying away when it's not being used
parent
536eb957
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
47 additions
and
7 deletions
+47
-7
Cython/Compiler/Nodes.py
Cython/Compiler/Nodes.py
+5
-7
tests/run/kwargs_passthrough.pyx
tests/run/kwargs_passthrough.pyx
+42
-0
No files found.
Cython/Compiler/Nodes.py
View file @
3f75d910
...
...
@@ -3380,7 +3380,7 @@ class DefNodeWrapper(FuncDefNode):
code
.
putln
(
"}"
)
if
self
.
starstar_arg
:
if
self
.
star_arg
:
if
self
.
star_arg
or
not
self
.
starstar_arg
.
entry
.
cf_used
:
kwarg_check
=
"unlikely(%s)"
%
Naming
.
kwds_cname
else
:
kwarg_check
=
"%s"
%
Naming
.
kwds_cname
...
...
@@ -3394,9 +3394,8 @@ class DefNodeWrapper(FuncDefNode):
kwarg_check
,
Naming
.
kwds_cname
,
self
.
name
,
bool
(
self
.
starstar_arg
),
self
.
error_value
()))
if
self
.
starstar_arg
:
allow_null
=
all
(
ref
.
node
.
allow_null
for
ref
in
self
.
starstar_arg
.
entry
.
cf_references
)
if
allow_null
:
if
self
.
starstar_arg
and
self
.
starstar_arg
.
entry
.
cf_used
:
if
all
(
ref
.
node
.
allow_null
for
ref
in
self
.
starstar_arg
.
entry
.
cf_references
):
code
.
putln
(
"if (%s) {"
%
kwarg_check
)
code
.
putln
(
"%s = PyDict_Copy(%s); if (unlikely(!%s)) return %s;"
%
(
self
.
starstar_arg
.
entry
.
cname
,
...
...
@@ -3405,12 +3404,11 @@ class DefNodeWrapper(FuncDefNode):
self
.
error_value
()))
code
.
put_gotref
(
self
.
starstar_arg
.
entry
.
cname
)
code
.
putln
(
"} else {"
)
code
.
putln
(
"%s = NULL;"
%
(
self
.
starstar_arg
.
entry
.
cname
,))
code
.
putln
(
"%s = NULL;"
%
(
self
.
starstar_arg
.
entry
.
cname
,))
code
.
putln
(
"}"
)
self
.
starstar_arg
.
entry
.
xdecref_cleanup
=
1
else
:
code
.
put
ln
(
"%s = (%s) ? PyDict_Copy(%s) : PyDict_New();
"
%
(
code
.
put
(
"%s = (%s) ? PyDict_Copy(%s) : PyDict_New();
"
%
(
self
.
starstar_arg
.
entry
.
cname
,
Naming
.
kwds_cname
,
Naming
.
kwds_cname
))
...
...
tests/run/kwargs_passthrough.pyx
View file @
3f75d910
...
...
@@ -19,6 +19,48 @@ def wrap_passthrough(f):
return
wrapper
@
cython
.
test_fail_if_path_exists
(
'//KeywordArgsNode'
)
def
unused
(
*
args
,
**
kwargs
):
"""
>>> unused()
()
>>> unused(1, 2)
(1, 2)
"""
return
args
@
cython
.
test_fail_if_path_exists
(
'//KeywordArgsNode'
)
def
used_in_closure
(
**
kwargs
):
"""
>>> used_in_closure()
>>> d = {}
>>> used_in_closure(**d)
>>> d # must not be modified
{}
"""
def
func
():
kwargs
[
'test'
]
=
1
return
func
()
@
cython
.
test_fail_if_path_exists
(
'//KeywordArgsNode'
)
def
modify_in_closure
(
**
kwargs
):
"""
>>> func = modify_in_closure()
>>> func()
>>> d = {}
>>> func = modify_in_closure(**d)
>>> func()
>>> d # must not be modified
{}
"""
def
func
():
kwargs
[
'test'
]
=
1
return
func
@
cython
.
test_assert_path_exists
(
'//KeywordArgsNode'
)
def
wrap_passthrough_more
(
f
):
"""
...
...
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