Commit 3f75d910 authored by Stefan Behnel's avatar Stefan Behnel

optimise **kwargs copying away when it's not being used

parent 536eb957
......@@ -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.putln("%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))
......
......@@ -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):
"""
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment