From 393b242f1ceeef1cc6c974116b4c41578f99931a Mon Sep 17 00:00:00 2001 From: "Jasper St. Pierre" Date: Thu, 28 Jun 2012 15:13:08 -0400 Subject: [PATCH] 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): -- 2.7.4