[ZPT] CVS: Packages/Products/PageTemplates (Products/DC/PageTemplates) - TALES.py:1.14

fred@digicool.com fred@digicool.com
Thu, 7 Jun 2001 10:51:45 -0400 (EDT)


Update of /cvs-repository/Packages/Products/PageTemplates
In directory korak.digicool.com:/tmp/cvs-serv15673

Modified Files:
	TALES.py 
Log Message:
SafeMapping:
    The _push() and _pop() methods aren't really any different from
    the push() and pop() methods from the base MultiMap, so we can use
    them directly to avoid a lot of looks and method invocation
    overhead, and it's easier to tell from the code that they are just
    a renaming.

Context.beginScope(), .endScope():
    Move an attribute access out of the loop since the attribute isn't
    re-bound inside the loop.

Context.evaluateText():
    Re-phrase the condition in the if statement to allow the runtime
    to perform fewer global name lookups when possible, and avoid the
    tuple construction completely.



--- Updated File TALES.py in package Packages/Products/PageTemplates --
--- TALES.py	2001/05/18 18:11:19	1.13
+++ TALES.py	2001/06/07 14:51:45	1.14
@@ -141,14 +141,11 @@
     '''
     __allow_access_to_unprotected_subobjects__ = 1
     push = pop = None
-    def _push(self, ob):
-        MultiMapping.push(self, ob)
-    def _pop(self, *args):
-        if args:
-            return apply(MultiMapping.pop, (self,) + args)
-        else:
-            return MultiMapping.pop(self)
-    def has_get(self, key):
+
+    _push = MultiMapping.push
+    _pop = MultiMapping.pop
+
+    def has_get(self, key, _marker=[]):
         v = self.get(key, _marker)
         if v is _marker:
             return 0, None
@@ -253,18 +250,19 @@
         oldctxts = self._current_ctxts
         self._ctxts_pushed.append(oldctxts)
         self._current_ctxts = ctxts = {}
+        contexts = self.contexts
         for ctxname in oldctxts.keys():
             # Push fresh namespace on each local stack.
             ctxts[ctxname] = ctx = {}
-            self.contexts[ctxname]._push(ctx)
+            contexts[ctxname]._push(ctx)
 
     def endScope(self):
         self._current_ctxts = ctxts = self._ctxts_pushed.pop()
         # Pop the ones that were pushed at the beginning of the scope.
+        contexts = self.contexts
         for ctxname in ctxts.keys():
-            ctx = self.contexts[ctxname]._pop()
-            # Make sure there's no circular garbage
-            ctx.clear()
+            # Pop, then make sure there's no circular garbage
+            contexts[ctxname]._pop().clear()
 
     def setLocal(self, name, value):
         self._current_ctxts['local'][name] = value
@@ -301,9 +299,9 @@
 
     def evaluateText(self, expr):
         text = self.evaluate(expr)
-        if text not in (None, Default):
-            text = str(text)
-        return text
+        if text is Default or text is None:
+            return text
+        return str(text)
 
     def evaluateStructure(self, expr):
         return self.evaluate(expr)