chiark / gitweb /
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 414e1a80e45ba9af6ee62a628e0b6f78c2af58f1..8377a7451b7d5febb735ba5089c5d786db1914f9 100644 (file)
@@ -433,12 +433,10 @@ (defmethod stream-read-line ((stream charbuf-scanner-stream))
       (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 --------------------------------------------------