summaryrefslogtreecommitdiff
path: root/giscanner
diff options
context:
space:
mode:
authorJohan Dahlin <johan@gnome.org>2010-09-20 10:35:48 -0300
committerJohan Dahlin <johan@gnome.org>2010-09-20 10:46:52 -0300
commit84aa7defdb1a3082021bd28a61803a1e140cf8ca (patch)
tree6228c57a55cee6b245d709511607f71103cf357b /giscanner
parent85594416e516f939cda4de4a35cee90812fe659c (diff)
downloadgobject-introspection-84aa7defdb1a3082021bd28a61803a1e140cf8ca.tar.gz
[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.
Diffstat (limited to 'giscanner')
-rw-r--r--giscanner/girparser.py44
-rw-r--r--giscanner/scannermain.py4
-rw-r--r--giscanner/transformer.py16
3 files changed, 45 insertions, 19 deletions
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))
diff --git a/giscanner/scannermain.py b/giscanner/scannermain.py
index 556e3c95..3a9f27c9 100644
--- a/giscanner/scannermain.py
+++ b/giscanner/scannermain.py
@@ -291,6 +291,10 @@ see --identifier-prefix and --symbol-prefix."""
transformer = Transformer(namespace,
accept_unprefixed=options.accept_unprefixed)
transformer.set_include_paths(options.include_paths)
+ if options.passthrough_gir:
+ transformer.disable_cache()
+ transformer.set_passthrough_mode()
+
shown_include_warning = False
for include in options.includes:
if os.sep in include:
diff --git a/giscanner/transformer.py b/giscanner/transformer.py
index be34ff5f..70addb26 100644
--- a/giscanner/transformer.py
+++ b/giscanner/transformer.py
@@ -54,6 +54,7 @@ class Transformer(object):
self._includes = {}
self._include_names = set()
self._includepaths = []
+ self._passthrough_mode = False
def get_includes(self):
return self._include_names
@@ -61,6 +62,12 @@ class Transformer(object):
def get_pkgconfig_packages(self):
return self._pkg_config_packages
+ def disable_cache(self):
+ self._cachestore = None
+
+ def set_passthrough_mode(self):
+ self._passthrough_mode = True
+
def _append_new_node(self, node):
original = self._namespace.get(node.name)
# Special case constants here; we allow duplication to sort-of
@@ -169,11 +176,14 @@ None."""
sys.exit(1)
def _parse_include(self, filename, uninstalled=False):
- parser = self._cachestore.load(filename)
+ parser = None
+ if self._cachestore is not None:
+ parser = self._cachestore.load(filename)
if parser is None:
- parser = GIRParser()
+ parser = GIRParser(types_only=not self._passthrough_mode)
parser.parse(filename)
- self._cachestore.store(filename, parser)
+ if self._cachestore is not None:
+ self._cachestore.store(filename, parser)
for include in parser.get_includes():
self.register_include(include)