[ZPT] CVS: Packages/TAL - TALGenerator.py:1.45

fred@digicool.com fred@digicool.com
Tue, 12 Jun 2001 17:58:36 -0400 (EDT)


Update of /cvs-repository/Packages/TAL
In directory korak.digicool.com:/tmp/cvs-serv2551

Modified Files:
	TALGenerator.py 
Log Message:

New optimization of the instruction stream:  beginScope/endScope
instructions are always pushed in front of text chunks; the affect of
this is that many text chunks previously separated by scope boundaries
are now joined together, causing fewer instructions to be generated.



--- Updated File TALGenerator.py in package Packages/TAL --
--- TALGenerator.py	2001/06/09 05:25:21	1.44
+++ TALGenerator.py	2001/06/12 21:58:36	1.45
@@ -140,6 +140,12 @@
             if opcode == "startEndTag":
                 if self.optimizeStartTag(collect, item[1], item[2], endsep):
                     continue
+            if opcode in ("beginScope", "endScope"):
+                # Push *Scope instructions in front of any text instructions;
+                # this allows text instructions separated only by *Scope
+                # instructions to be joined together.
+                output.append(self.optimizeArgsList(item))
+                continue
             text = string.join(collect, "")
             if text:
                 i = string.rfind(text, "\n")
@@ -149,13 +155,16 @@
                 else:
                     output.append(("rawtextOffset", (text, len(text))))
             if opcode != None:
-                if len(item) == 2:
-                    output.append((opcode, item[1]))
-                else:
-                    output.append((opcode, tuple(item[1:])))
+                output.append(self.optimizeArgsList(item))
             rawseen = cursor+1
             collect = []
         return output
+
+    def optimizeArgsList(self, item):
+        if len(item) == 2:
+            return item
+        else:
+            return item[0], tuple(item[1:])
 
     actionIndex = {"replace":0, "insert":1, "metal":2, "tal":3, "xmlns":4,
                    0: 0, 1: 1, 2: 2, 3: 3, 4: 4}