summaryrefslogtreecommitdiffstats
path: root/Tools
diff options
context:
space:
mode:
authorSerhiy Storchaka <storchaka@gmail.com>2016-08-14 07:52:18 (GMT)
committerSerhiy Storchaka <storchaka@gmail.com>2016-08-14 07:52:18 (GMT)
commit9171a8b4cea3e7b30e4f2c0a989d7f7b8ffabe73 (patch)
tree5cc9c9243ba4ef93902fafdc624e56eab3b15842 /Tools
parentb6f78c2755489dfcbe4898072ef0cd7dca11ff3d (diff)
downloadcpython-9171a8b4cea3e7b30e4f2c0a989d7f7b8ffabe73.zip
cpython-9171a8b4cea3e7b30e4f2c0a989d7f7b8ffabe73.tar.gz
cpython-9171a8b4cea3e7b30e4f2c0a989d7f7b8ffabe73.tar.bz2
Issue #27574: Decreased an overhead of parsing keyword arguments in functions
implemented with using Argument Clinic.
Diffstat (limited to 'Tools')
-rwxr-xr-xTools/clinic/clinic.py14
1 files changed, 6 insertions, 8 deletions
diff --git a/Tools/clinic/clinic.py b/Tools/clinic/clinic.py
index f9ba16c..282b1a0 100755
--- a/Tools/clinic/clinic.py
+++ b/Tools/clinic/clinic.py
@@ -743,7 +743,10 @@ class CLanguage(Language):
return output()
def insert_keywords(s):
- return linear_format(s, declarations="static char *_keywords[] = {{{keywords}, NULL}};\n{declarations}")
+ return linear_format(s, declarations=
+ 'static const char * const _keywords[] = {{{keywords}, NULL}};\n'
+ 'static _PyArg_Parser _parser = {{"{format_units}:{name}", _keywords, 0}};\n'
+ '{declarations}')
if not parameters:
# no parameters, METH_NOARGS
@@ -849,17 +852,12 @@ class CLanguage(Language):
parser_prototype = parser_prototype_keyword
body = normalize_snippet("""
- if (!PyArg_ParseTupleAndKeywords(args, kwargs, "{format_units}:{name}", _keywords,
+ if (!_PyArg_ParseTupleAndKeywordsFast(args, kwargs, &_parser,
{parse_arguments})) {{
goto exit;
}}
""", indent=4)
- parser_definition = parser_body(parser_prototype, normalize_snippet("""
- if (!PyArg_ParseTupleAndKeywords(args, kwargs, "{format_units}:{name}", _keywords,
- {parse_arguments})) {{
- goto exit;
- }}
- """, indent=4))
+ parser_definition = parser_body(parser_prototype, body)
parser_definition = insert_keywords(parser_definition)