Commit b692ef71 authored by Stefan Behnel's avatar Stefan Behnel

code simplification

parent 1d0b3e33
...@@ -2126,9 +2126,10 @@ class DefNode(FuncDefNode): ...@@ -2126,9 +2126,10 @@ class DefNode(FuncDefNode):
for i, arg in enumerate(all_args): for i, arg in enumerate(all_args):
if not arg.default: if not arg.default:
last_required_arg = i last_required_arg = i
code.putln('switch (PyTuple_GET_SIZE(%s)) {' % Naming.args_cname) if max_positional_args > 0:
code.putln('switch (PyTuple_GET_SIZE(%s)) {' % Naming.args_cname)
for i, arg in enumerate(all_args[:last_required_arg+1]): for i, arg in enumerate(all_args[:last_required_arg+1]):
if i <= max_positional_args: if max_positional_args > 0 and i <= max_positional_args:
if self.star_arg and i == max_positional_args: if self.star_arg and i == max_positional_args:
code.putln('default:') code.putln('default:')
else: else:
...@@ -2138,8 +2139,8 @@ class DefNode(FuncDefNode): ...@@ -2138,8 +2139,8 @@ class DefNode(FuncDefNode):
continue continue
code.putln('values[%d] = PyDict_GetItem(%s, %s);' % ( code.putln('values[%d] = PyDict_GetItem(%s, %s);' % (
i, Naming.kwds_cname, arg.name_entry.pystring_cname)) i, Naming.kwds_cname, arg.name_entry.pystring_cname))
code.putln('if (likely(values[%d])) kw_args--;' % i);
if i < min_positional_args: if i < min_positional_args:
code.putln('if (likely(values[%d])) kw_args--;' % i);
if i == 0: if i == 0:
# special case: we know arg 0 is missing # special case: we know arg 0 is missing
code.put('else ') code.put('else ')
...@@ -2154,15 +2155,14 @@ class DefNode(FuncDefNode): ...@@ -2154,15 +2155,14 @@ class DefNode(FuncDefNode):
min_positional_args, max_positional_args, i)) min_positional_args, max_positional_args, i))
code.putln(code.error_goto(self.pos)) code.putln(code.error_goto(self.pos))
code.putln('}') code.putln('}')
else: elif arg.kw_only:
code.putln('if (values[%d]) kw_args--;' % i); code.putln('else {')
if arg.kw_only and not arg.default: code.put('__Pyx_RaiseKeywordRequired("%s", %s); ' %(
code.putln('else {') self.name.utf8encode(), arg.name_entry.pystring_cname))
code.put('__Pyx_RaiseKeywordRequired("%s", %s); ' %( code.putln(code.error_goto(self.pos))
self.name.utf8encode(), arg.name_entry.pystring_cname)) code.putln('}')
code.putln(code.error_goto(self.pos)) if max_positional_args > 0:
code.putln('}') code.putln('}')
code.putln('}')
code.putln('if (unlikely(kw_args > 0)) {') code.putln('if (unlikely(kw_args > 0)) {')
# non-positional kw args left in dict: default args, **kwargs or error # non-positional kw args left in dict: default args, **kwargs or error
......
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