Commit 57d4d305 authored by Stefan Behnel's avatar Stefan Behnel

avoid generating inlined keyword unpacking code when signature has only optional arguments

parent 4cd97c23
...@@ -2055,49 +2055,48 @@ class DefNode(FuncDefNode): ...@@ -2055,49 +2055,48 @@ class DefNode(FuncDefNode):
code.putln('}') code.putln('}')
# now fill up the required arguments with values from the kw dict # now fill up the required arguments with values from the kw dict
code.putln('switch (PyTuple_GET_SIZE(%s)) {' % Naming.args_cname) last_required_arg = -1
needs_break = False
for i, arg in enumerate(all_args): for i, arg in enumerate(all_args):
if i <= max_positional_args: if not arg.default:
if self.star_arg and i == max_positional_args: last_required_arg = i
code.putln('default:') if last_required_arg >= 0:
else: code.putln('switch (PyTuple_GET_SIZE(%s)) {' % Naming.args_cname)
code.putln('case %2d:' % i) for i, arg in enumerate(all_args[:last_required_arg+1]):
if arg.default: if i <= max_positional_args:
# handled in ParseOptionalKeywords() below if self.star_arg and i == max_positional_args:
needs_break = True code.putln('default:')
continue else:
else: code.putln('case %2d:' % i)
needs_break = False if arg.default:
code.putln('values[%d] = PyDict_GetItem(%s, %s);' % ( # handled in ParseOptionalKeywords() below
i, Naming.kwds_cname, arg.name_entry.pystring_cname)) continue
if i < min_positional_args: code.putln('values[%d] = PyDict_GetItem(%s, %s);' % (
code.putln('if (likely(values[%d])) kw_args--;' % i); i, Naming.kwds_cname, arg.name_entry.pystring_cname))
if i == 0: if i < min_positional_args:
# special case: we know arg 0 is missing code.putln('if (likely(values[%d])) kw_args--;' % i);
code.put('else ') if i == 0:
code.put_goto(argtuple_error_label) # special case: we know arg 0 is missing
code.put('else ')
code.put_goto(argtuple_error_label)
else:
# print the correct number of values (args or
# kwargs) that were passed into positional
# arguments up to this point
code.putln('else {')
code.put('__Pyx_RaiseArgtupleInvalid("%s", %d, %d, %d, %d); ' % (
self.name.utf8encode(), has_fixed_positional_count,
min_positional_args, max_positional_args, i))
code.putln(code.error_goto(self.pos))
code.putln('}')
else: else:
# print the correct number of values (args or code.putln('if (values[%d]) kw_args--;' % i);
# kwargs) that were passed into positional if arg.kw_only and not arg.default:
# arguments up to this point code.putln('else {')
code.putln('else {') code.put('__Pyx_RaiseKeywordRequired("%s", %s); ' %(
code.put('__Pyx_RaiseArgtupleInvalid("%s", %d, %d, %d, %d); ' % ( self.name.utf8encode(), arg.name_entry.pystring_cname))
self.name.utf8encode(), has_fixed_positional_count, code.putln(code.error_goto(self.pos))
min_positional_args, max_positional_args, i)) code.putln('}')
code.putln(code.error_goto(self.pos)) code.putln('}')
code.putln('}')
else:
code.putln('if (values[%d]) kw_args--;' % i);
if arg.kw_only and not arg.default:
code.putln('else {')
code.put('__Pyx_RaiseKeywordRequired("%s", %s); ' %(
self.name.utf8encode(), arg.name_entry.pystring_cname))
code.putln(code.error_goto(self.pos))
code.putln('}')
if needs_break:
code.putln('break;')
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