]> granicus.if.org Git - python/commitdiff
Bug #1586448: the compiler module now emits the same bytecode for
authorGeorg Brandl <georg@python.org>
Sun, 29 Oct 2006 08:53:06 +0000 (08:53 +0000)
committerGeorg Brandl <georg@python.org>
Sun, 29 Oct 2006 08:53:06 +0000 (08:53 +0000)
list comprehensions as the builtin compiler, using the LIST_APPEND
opcode.

Lib/compiler/pycodegen.py
Misc/NEWS

index 009438da6d8eba9461c1963539c618ad2ad49416..0e226fdbcfe713ef5d534076a6087452b6605afd 100644 (file)
@@ -573,12 +573,11 @@ class CodeGenerator:
     def visitListComp(self, node):
         self.set_lineno(node)
         # setup list
-        append = "$append%d" % self.__list_count
+        tmpname = "$list%d" % self.__list_count
         self.__list_count = self.__list_count + 1
         self.emit('BUILD_LIST', 0)
         self.emit('DUP_TOP')
-        self.emit('LOAD_ATTR', 'append')
-        self._implicitNameOp('STORE', append)
+        self._implicitNameOp('STORE', tmpname)
 
         stack = []
         for i, for_ in zip(range(len(node.quals)), node.quals):
@@ -590,10 +589,9 @@ class CodeGenerator:
                 self.visit(if_, cont)
             stack.insert(0, (start, cont, anchor))
 
-        self._implicitNameOp('LOAD', append)
+        self._implicitNameOp('LOAD', tmpname)
         self.visit(node.expr)
-        self.emit('CALL_FUNCTION', 1)
-        self.emit('POP_TOP')
+        self.emit('LIST_APPEND',)
 
         for start, cont, anchor in stack:
             if cont:
@@ -604,7 +602,7 @@ class CodeGenerator:
                 self.nextBlock(skip_one)
             self.emit('JUMP_ABSOLUTE', start)
             self.startBlock(anchor)
-        self._implicitNameOp('DELETE', append)
+        self._implicitNameOp('DELETE', tmpname)
 
         self.__list_count = self.__list_count - 1
 
index 605a862aebc1cea8d5cad2f2100e606dfd46718e..8cb10fafd71c40d910145451d2120c5bd6939222 100644 (file)
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -89,6 +89,10 @@ Core and builtins
 Library
 -------
 
+- Bug #1586448: the compiler module now emits the same bytecode for
+  list comprehensions as the builtin compiler, using the LIST_APPEND
+  opcode.
+
 - Fix codecs.EncodedFile which did not use file_encoding in 2.5.0, and
   fix all codecs file wrappers to work correctly with the "with"
   statement (bug #1586513).