No swap function in Python?

Nick Perkins nperkins7 at home.com
Wed May 30 20:16:49 EDT 2001


"(a,b) = (b,a)" compiles to (approximately):
>
>     LOAD_FAST b
>     LOAD_FAST a
>     BUILD_TUPLE 2
>     UNPACK_TUPLE 2
>     STORE_FAST a
>     STORE_FAST b
>
> It's easy to see how you can use the runtime stack without going through
the
> BUILD/UNPACK pair:
>
>     LOAD_FAST b
>     LOAD_FAST a
>     STORE_FAST b
>     STORE_FAST a
>
> Any peephole optimizer can do this for you... ;-)
>
> Skip

..that looks a lot faster than the 'normal' way!
(maybe there should be a built-in operator or something to do exactly that)

..what is a peephole optimizer? and where can I get one?







More information about the Python-list mailing list