[Zope3-checkins] SVN: Zope3/branches/jim-adapter-alt1/src/zope/interface/adapter.py Small optimization of single-adapter case.

Jim Fulton jim at zope.com
Sun Jan 29 20:03:21 EST 2006


Log message for revision 41489:
  Small optimization of single-adapter case.
  

Changed:
  U   Zope3/branches/jim-adapter-alt1/src/zope/interface/adapter.py

-=-
Modified: Zope3/branches/jim-adapter-alt1/src/zope/interface/adapter.py
===================================================================
--- Zope3/branches/jim-adapter-alt1/src/zope/interface/adapter.py	2006-01-30 00:03:15 UTC (rev 41488)
+++ Zope3/branches/jim-adapter-alt1/src/zope/interface/adapter.py	2006-01-30 01:03:21 UTC (rev 41489)
@@ -342,13 +342,27 @@
         return result        
     
     def lookup1(self, required, provided, name=u'', default=None):
-        return self.lookup((required, ), provided, name, default)
+        cache = self._getcache(provided, name)
+        result = cache.get(required, _not_in_mapping)
+        if result is _not_in_mapping:
+            return self.lookup((required, ), provided, name, default)
+
+        if result is None:
+            return default
+
+        return result
+
     
     def queryAdapter(self, object, provided, name=u'', default=None):
         return self.adapter_hook(provided, object, name, default)
 
     def adapter_hook(self, provided, object, name=u'', default=None):
-        factory = self.lookup1(providedBy(object), provided, name)
+        required = providedBy(object)
+        cache = self._getcache(provided, name)
+        factory = cache.get(required, _not_in_mapping)
+        if factory is _not_in_mapping:
+            factory = self.lookup((required, ), provided, name)
+
         if factory is not None:
             result = factory(object)
             if result is not None:



More information about the Zope3-Checkins mailing list