src/parser/scanner-charbuf-impl.lisp: Simplify `stream-read-line'.
authorMark Wooding <mdw@distorted.org.uk>
Sun, 30 Aug 2015 09:58:38 +0000 (10:58 +0100)
committerMark Wooding <mdw@distorted.org.uk>
Thu, 17 Sep 2015 10:29:51 +0000 (11:29 +0100)
We do more or less the same stuff at the end regardless of how we got
there, so factor it out.

src/parser/scanner-charbuf-impl.lisp

index 414e1a8..8377a74 100644 (file)
       (flet ((snarf (buf start end)
               (let ((pos (position #\newline buf :start start :end end)))
                 (push (make-charbuf-slice buf start (or pos end)) slices)
-                (if pos
-                    (values (concatenate-charbuf-slices (nreverse slices))
-                            (1+ pos))
-                    (values nil 0))))
-            (fail ()
-              (values (concatenate-charbuf-slices (nreverse slices)) t)))
-       (charbuf-scanner-map scanner #'snarf #'fail)))))
+                (values pos (and pos (1+ pos))))))
+       (multiple-value-bind (result eofp)
+           (charbuf-scanner-map scanner #'snarf)
+         (declare (ignore result))
+         (values (concatenate-charbuf-slices (nreverse slices))) eofp)))))
 
 ;;;----- That's all, folks --------------------------------------------------