Python的字节码(2.5版)中优化了多少个位置 [英] how many places are optimized in Python's bytecode(version 2.5)

查看:66
本文介绍了Python的字节码(2.5版)中优化了多少个位置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

谁能告诉我在Python的字节码中优化了多少个地方?
这些天我一直在尝试反编译Python的字节码,但是我发现在Python的2.5版中有很多优化。例如:这段代码

Can anyone tell me how many places there are optimized in Python's bytecode? I was trying to de-compile Python's bytecode these days,but I found that in Python's version 2.5 there are a lot of optimization.For example: to this code

a,b,c=([],[],[])#build list

版本2.5之前的非优化字节码如下:

the non-optimized bytecode before version2.5 is like that:

BUILD_LIST_0
BUILD_LIST_0
BUILD_LIST_0
BUILD_LIST_4
UNPACK_LIST_
STORE_NAME 'a'
STORE_NAME 'b'
STORE_NAME 'c'

在版本2.5中,优化的字节码如下:

In the version2.5,the optimized bytecode is like this:

BUILD_LIST_0
BUILD_LIST_0
BUILD_LIST_0
ROT_THREE
ROT_TWO
STORE_FAST 'a'
STORE_FAST 'b'
STORE_FAST 'c'

这仅是一个示例,但还有许多其他地方可以进行优化。因此,有人知道是否有一些文档来阐明这些优化或告诉我可以找到所有这些优化方法吗?

This is only one example,but there are many other places may be optimized. So,does anybode know is there some documentation to clarify these optimization or tell me in which way I can find all of them?

推荐答案

Python / peephole.c 源文件基本上就是所有这些优化都已执行-我给出的链接是当前版本(2.6或更高版本),因为我无法访问动态源浏览器此处,但是一旦它再次起作用,就很容易看到特定的版本,例如现存的(例如)2.5.2或其他特定版本。版本,您需要此信息。

The Python/peephole.c source file is where basically all such optimizations are performed -- the link I gave is to the current version (2.6 or better), because I'm having trouble getting to the dynamic source browser here, but once it works again it's easy to see specific versions such as the one that was extant for (say) 2.5.2 or whatever other specific version you need this information for.

这篇关于Python的字节码(2.5版)中优化了多少个位置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆