[pypy-svn] r18202 - pypy/dist/pypy/interpreter/astcompiler

ac at codespeak.net ac at codespeak.net
Wed Oct 5 18:17:59 CEST 2005


Author: ac
Date: Wed Oct  5 18:17:58 2005
New Revision: 18202

Modified:
   pypy/dist/pypy/interpreter/astcompiler/pycodegen.py
Log:
Minor optimization.

Modified: pypy/dist/pypy/interpreter/astcompiler/pycodegen.py
==============================================================================
--- pypy/dist/pypy/interpreter/astcompiler/pycodegen.py	(original)
+++ pypy/dist/pypy/interpreter/astcompiler/pycodegen.py	Wed Oct  5 18:17:58 2005
@@ -135,6 +135,12 @@
             return 1
     return 0
 
+def is_constant_true(space, node):
+    if isinstance(node, ast.Const):
+        if space.is_true(node.value):
+            return 1
+    return 0
+
 class CodeGenerator(ast.ASTVisitor):
     """Defines basic code generator for Python bytecode
     """
@@ -428,11 +434,14 @@
         self.setups.append((LOOP, loop))
 
         self.set_lineno(node, force=True)
-        node.test.accept( self )
-        self.emitop_block('JUMP_IF_FALSE', else_ or after)
+        if is_constant_true(self.space, node.test):
+            self.nextBlock()
+        else:
+            node.test.accept( self )
+            self.emitop_block('JUMP_IF_FALSE', else_ or after)
 
-        self.nextBlock()
-        self.emit('POP_TOP')
+            self.nextBlock()
+            self.emit('POP_TOP')
         node.body.accept( self )
         self.emitop_block('JUMP_ABSOLUTE', loop)
 



More information about the Pypy-commit mailing list