Commit 39172312 authored by Stefan Behnel's avatar Stefan Behnel

refactor utility code inclusion for optimised unbound method calls

parent 7a6c4e2a
...@@ -419,26 +419,28 @@ class UtilityCode(UtilityCodeBase): ...@@ -419,26 +419,28 @@ class UtilityCode(UtilityCodeBase):
if 'CALL_UNBOUND_METHOD(' not in impl: if 'CALL_UNBOUND_METHOD(' not in impl:
return False, impl return False, impl
replacements = [] utility_code = set()
def externalise(matchobj): def externalise(matchobj):
type_cname, method_name, args = matchobj.groups() type_cname, method_name, args = matchobj.groups()
args = [arg.strip() for arg in args[1:].split(',')] args = [arg.strip() for arg in args[1:].split(',')]
if len(args) == 1: if len(args) == 1:
call = '__Pyx_CallUnboundCMethod0' call = '__Pyx_CallUnboundCMethod0'
output.use_utility_code(UtilityCode.load_cached("CallUnboundCMethod0", "ObjectHandling.c")) utility_code.add("CallUnboundCMethod0")
elif len(args) == 2: elif len(args) == 2:
call = '__Pyx_CallUnboundCMethod1' call = '__Pyx_CallUnboundCMethod1'
output.use_utility_code(UtilityCode.load_cached("CallUnboundCMethod1", "ObjectHandling.c")) utility_code.add("CallUnboundCMethod1")
else: else:
assert False, "CALL_UNBOUND_METHOD() requires 1 or 2 call arguments" assert False, "CALL_UNBOUND_METHOD() requires 1 or 2 call arguments"
cname = output.get_cached_unbound_method(type_cname, method_name, len(args)) cname = output.get_cached_unbound_method(type_cname, method_name, len(args))
replacements.append(cname)
return '%s(&%s, %s)' % (call, cname, ', '.join(args)) return '%s(&%s, %s)' % (call, cname, ', '.join(args))
impl = re.sub(r'CALL_UNBOUND_METHOD\(([a-zA-Z_]+),\s*"([^"]+)"((?:,\s*[^),]+)+)\)', externalise, impl) impl = re.sub(r'CALL_UNBOUND_METHOD\(([a-zA-Z_]+),\s*"([^"]+)"((?:,\s*[^),]+)+)\)', externalise, impl)
assert 'CALL_UNBOUND_METHOD(' not in impl assert 'CALL_UNBOUND_METHOD(' not in impl
return bool(replacements), impl
for helper in sorted(utility_code):
output.use_utility_code(UtilityCode.load_cached(helper, "ObjectHandling.c"))
return bool(utility_code), impl
def wrap_c_strings(self, impl): def wrap_c_strings(self, impl):
"""Replace CSTRING('''xyz''') by a C compatible string """Replace CSTRING('''xyz''') by a C compatible string
......
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