-;;; maps into TO-SEQ from elements of FROM-SEQ via MAPPER. MAPPER
-;;; returns two values: the number of elments stored in TO-SEQ, and
-;;; the number used up from FROM-SEQ. MAPPER is responsible for
-;;; getting out if either sequence runs out of room.
-(declaim (inline varimap))
-(defun varimap (to-seq to-start to-end from-start from-end mapper)
- (declare (optimize speed (safety 0))
- (type array-range to-start to-end from-start from-end)
- (type function mapper))
- (loop with from-size of-type array-range = 0
- and to-size of-type array-range = 0
- for to-pos of-type array-range = to-start then (+ to-pos to-size)
- for from-pos of-type array-range = from-start then (+ from-pos from-size)
- while (and (< to-pos to-end)
- (< from-pos from-end))
- do (multiple-value-bind (ts fs) (funcall mapper to-pos from-pos)
- (setf to-size ts
- from-size fs))
- finally (return (values to-seq to-pos from-pos))))
-