next up previous contents
Next: 5.4.7 Source to Source Up: 5.4 Source Optimization Previous: 5.4.5 Unreachable Code Deletion

5.4.6 Multiple Values Optimization

   

Within a function, Python implements uses of multiple values particularly efficiently. Multiple values can be kept in arbitrary registers, so using multiple values doesn't imply stack manipulation and representation conversion. For example, this code:

(let ((a (if x (foo x) u))
      (b (if x (bar x) v)))
  ...)
is actually more efficient written this way:
(multiple-value-bind
    (a b)
    (if x
        (values (foo x) (bar x))
        (values u v))
  ...)

Also, see section 5.6.5 for information on how local call provides efficient support for multiple function return values.



Raymond Toy
Mon Jul 14 09:11:27 EDT 1997