[kupfer: 22/31] qfurl: Return immediately on first match resolved



commit 24a718c41ff2d2ad67663eaa779ca65fa23e2842
Author: Ulrik Sverdrup <ulrik sverdrup gmail com>
Date:   Wed Dec 30 22:41:09 2009 +0100

    qfurl: Return immediately on first match resolved
    
    It is possible to speed up the lookup quite a lot, by simply returning
    on the first match found (since that's the one we would return
    anyway). It's even often so that if we find more than occurrence it's
    the exact same object -- which does not motivate the expense.

 kupfer/qfurl.py |   14 ++++++++------
 1 files changed, 8 insertions(+), 6 deletions(-)
---
diff --git a/kupfer/qfurl.py b/kupfer/qfurl.py
index 590d8ee..c3f4048 100644
--- a/kupfer/qfurl.py
+++ b/kupfer/qfurl.py
@@ -89,10 +89,11 @@ class qfurl (object):
 		return mother, qfid, typname
 
 	def resolve_in_catalog(self, catalog):
-		"""Resolve self in a catalog of sources"""
+		"""Resolve self in a catalog of sources
+
+		Return *immediately* on match found"""
 		mother, qfid, typname = self._parts_mother_id_typename(self.url)
 		module, name = typname.rsplit(".", 1) if typname else (None, None)
-		matches = []
 		for src in catalog:
 			if name:
 				if name not in (pt.__name__
@@ -106,12 +107,13 @@ class qfurl (object):
 					continue
 				try:
 					if self == qfurl(obj):
-						matches.append(obj)
+						pretty.print_debug(__name__,
+							"Found", repr(obj), "for", self)
+						return obj
 				except QfurlError:
 					pass
-		pretty.print_debug(__name__, "Found matches:", matches)
-		pretty.print_debug(__name__, "For", self)
-		return matches[0] if matches else None
+		pretty.print_debug(__name__, "No match found for", self)
+		return None
 
 if __name__ == '__main__':
 	import doctest



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]