From 84aa7defdb1a3082021bd28a61803a1e140cf8ca Mon Sep 17 00:00:00 2001 From: Johan Dahlin Date: Mon, 20 Sep 2010 10:35:48 -0300 Subject: [scanner] Only store types in cache store Only store types that can be referenced in the cache store this reduces the size of the serialized Gtk-3.0.gir in the store from 5.7M to 366k on my system. It also reduces the time it takes to create a gir in gtksourceview by 35% and the time to run the warnings test by more than 50% This also disables the cache for passthrough mode since it needs access to the whole serialized tree. --- giscanner/girparser.py | 44 ++++++++++++++++++++++++++++---------------- 1 file changed, 28 insertions(+), 16 deletions(-) (limited to 'giscanner/girparser.py') diff --git a/giscanner/girparser.py b/giscanner/girparser.py index aedae3d3..8b638bf1 100644 --- a/giscanner/girparser.py +++ b/giscanner/girparser.py @@ -44,7 +44,8 @@ def _cns(tag): class GIRParser(object): - def __init__(self): + def __init__(self, types_only=False): + self._types_only = types_only self._shared_libraries = [] self._includes = set() self._pkgconfig_packages = set() @@ -149,8 +150,6 @@ class GIRParser(object): _corens('bitfield'): self._parse_enumeration_bitfield, _corens('callback'): self._parse_callback, _corens('class'): self._parse_object_interface, - _corens('constant'): self._parse_constant, - _corens('function'): self._parse_function, _corens('enumeration'): self._parse_enumeration_bitfield, _corens('interface'): self._parse_object_interface, _corens('record'): self._parse_record, @@ -158,6 +157,10 @@ class GIRParser(object): _glibns('boxed'): self._parse_boxed, } + if not self._types_only: + parser_methods[_corens('constant')] = self._parse_constant + parser_methods[_corens('function')] = self._parse_function + for node in ns.getchildren(): method = parser_methods.get(node.tag) if method is not None: @@ -184,6 +187,11 @@ class GIRParser(object): def _parse_generic_attribs(self, node, obj): assert isinstance(obj, ast.Annotated) + introspectable = node.attrib.get('introspectable') + if introspectable: + obj.introspectable = int(introspectable) > 0 + if self._types_only: + return doc = node.find(_corens('doc')) if doc is not None: obj.doc = doc.text @@ -193,9 +201,6 @@ class GIRParser(object): deprecated = node.attrib.get('deprecated') if deprecated: obj.deprecated = deprecated - introspectable = node.attrib.get('introspectable') - if introspectable: - obj.introspectable = int(introspectable) > 0 def _parse_object_interface(self, node): parent = node.attrib.get('parent') @@ -227,6 +232,8 @@ class GIRParser(object): obj.glib_type_struct = self._namespace.type_from_name(type_struct) self._namespace.append(obj) + if self._types_only: + return for iface in self._find_children(node, _corens('implements')): obj.interfaces.append(self._namespace.type_from_name(iface.attrib['name'])) for iface in self._find_children(node, _corens('prerequisite')): @@ -340,16 +347,17 @@ class GIRParser(object): if node.attrib.get('foreign') == '1': compound.foreign = True self._parse_generic_attribs(node, compound) - compound.fields.extend(self._parse_fields(node)) - for method in self._find_children(node, _corens('method')): - compound.methods.append( - self._parse_function_common(method, ast.Function)) - for func in self._find_children(node, _corens('function')): - compound.static_methods.append( - self._parse_function_common(func, ast.Function)) - for ctor in self._find_children(node, _corens('constructor')): - compound.constructors.append( - self._parse_function_common(ctor, ast.Function)) + if not self._types_only: + compound.fields.extend(self._parse_fields(node)) + for method in self._find_children(node, _corens('method')): + compound.methods.append( + self._parse_function_common(method, ast.Function)) + for func in self._find_children(node, _corens('function')): + compound.static_methods.append( + self._parse_function_common(func, ast.Function)) + for ctor in self._find_children(node, _corens('constructor')): + compound.constructors.append( + self._parse_function_common(ctor, ast.Function)) return compound def _parse_record(self, node, anonymous=False): @@ -444,6 +452,8 @@ class GIRParser(object): c_symbol_prefix=node.attrib.get(_cns('symbol-prefix'))) self._parse_generic_attribs(node, obj) self._namespace.append(obj) + if self._types_only: + return for method in self._find_children(node, _corens('method')): func = self._parse_function_common(method, ast.Function) func.is_method = True @@ -529,5 +539,7 @@ class GIRParser(object): self._parse_generic_attribs(node, obj) self._namespace.append(obj) + if self._types_only: + return for member in self._find_children(node, _corens('member')): members.append(self._parse_member(member)) -- cgit v1.2.1