[gobject-introspection] scanner: Don't use an O(N) lookup when we already have a hashmap
- From: Jasper St. Pierre <jstpierre src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gobject-introspection] scanner: Don't use an O(N) lookup when we already have a hashmap
- Date: Thu, 28 Jun 2012 21:34:35 +0000 (UTC)
commit 393b242f1ceeef1cc6c974116b4c41578f99931a
Author: Jasper St. Pierre <jstpierre mecheye net>
Date: Thu Jun 28 15:13:08 2012 -0400
scanner: Don't use an O(N) lookup when we already have a hashmap
This is a general code cleanup.
giscanner/ast.py | 1 +
giscanner/transformer.py | 11 ++++-------
2 files changed, 5 insertions(+), 7 deletions(-)
---
diff --git a/giscanner/ast.py b/giscanner/ast.py
index cab3807..91c6559 100644
--- a/giscanner/ast.py
+++ b/giscanner/ast.py
@@ -822,6 +822,7 @@ class Compound(Node, Registered):
def add_gtype(self, gtype_name, get_type):
self.gtype_name = gtype_name
self.get_type = get_type
+ self.namespace.type_names[gtype_name] = self
def _walk(self, callback, chain):
for ctor in self.constructors:
diff --git a/giscanner/transformer.py b/giscanner/transformer.py
index cb785e7..834fbac 100644
--- a/giscanner/transformer.py
+++ b/giscanner/transformer.py
@@ -836,13 +836,10 @@ Note that type resolution may not succeed."""
def _resolve_type_from_gtype_name(self, typeval):
assert typeval.gtype_name is not None
for ns in self._iter_namespaces():
- for node in ns.itervalues():
- if not (isinstance(node, (ast.Class, ast.Interface))
- or (isinstance(node, ast.Registered) and node.get_type is not None)):
- continue
- if node.gtype_name == typeval.gtype_name:
- typeval.target_giname = '%s.%s' % (ns.name, node.name)
- return True
+ node = ns.type_names.get(typeval.gtype_name, None)
+ if node is not None:
+ typeval.target_giname = '%s.%s' % (ns.name, node.name)
+ return True
return False
def resolve_type(self, typeval):
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]