Next: , Previous: , Up: Source Optimization   [Contents][Index]


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 local-call-return for information on how local call provides efficient support for multiple function return values.