# HG changeset patch # User Steve Losh # Date 1545797607 18000 # Node ID 0b3e65bdbab938fb8600949fc0135a70f21384cc # Parent 8892239d48346e600fa769e74f42df03dddf997e Clean up diff -r 8892239d4834 -r 0b3e65bdbab9 src/main.lisp --- a/src/main.lisp Tue Dec 25 22:55:18 2018 -0500 +++ b/src/main.lisp Tue Dec 25 23:13:27 2018 -0500 @@ -39,22 +39,22 @@ :do (write-char char result))) (defun read-field (stream delimiter result) - "Read and return a single field from `stream` into `result`." - (let* ((field (case (peek-char nil stream nil :eof) - (#\" (read-quoted-field stream delimiter result) t) - (#\newline (read-char stream) nil) - (:eof nil) - (t (read-unquoted-field stream delimiter result) t))) - (done (cond - ((null field) t) ; empty field at the end - ((read-char-if delimiter stream nil) nil) ; normal field - ((read-char-if #\newline stream nil #\newline) t) ; last field - (t (error "Bad data after field ~S: ~S" - field (peek-char nil stream)))))) - (values (if field - (get-output-stream-string result) - "") - done))) + "Read and return a single field from `stream` using `result`. + + Returns two values: a string of the field and a boolean denoting whether + we're done reading this row. + + " + (case (peek-char nil stream nil :eof) + (#\" (read-quoted-field stream delimiter result)) + ((#\newline :eof) nil) + (t (read-unquoted-field stream delimiter result))) + (let ((next (peek-char nil stream nil :eof))) + (values (get-output-stream-string result) + (cond ((eql next :eof) t) + ((eql next #\newline) (read-char stream) t) + ((eql next delimiter) (read-char stream) nil) + (t (error "Bad data after field: ~S" next)))))) (defun read-row% (stream delimiter eof-error-p eof-value) (if (eql :eof (peek-char nil stream eof-error-p :eof)) diff -r 8892239d4834 -r 0b3e65bdbab9 test/bench.lisp --- a/test/bench.lisp Tue Dec 25 22:55:18 2018 -0500 +++ b/test/bench.lisp Tue Dec 25 23:13:27 2018 -0500 @@ -81,9 +81,9 @@ #+sbcl (sb-ext:gc :full t) (write-file-this) - (write-line "Benchmarking cl-csv (writing).") - #+sbcl (sb-ext:gc :full t) - (write-file-cl-csv) + ;; (write-line "Benchmarking cl-csv (writing).") + ;; #+sbcl (sb-ext:gc :full t) + ;; (write-file-cl-csv) (write-line "Benchmarking fare-csv (writing).") #+sbcl (sb-ext:gc :full t) @@ -149,9 +149,9 @@ #+sbcl (sb-ext:gc :full t) (format t "Read ~D rows.~2%" (read-file-this)) - (write-line "Benchmarking cl-csv (reading).") - #+sbcl (sb-ext:gc :full t) - (format t "Read ~D rows.~2%" (read-file-cl-csv)) + ;; (write-line "Benchmarking cl-csv (reading).") + ;; #+sbcl (sb-ext:gc :full t) + ;; (format t "Read ~D rows.~2%" (read-file-cl-csv)) (write-line "Benchmarking fare-csv (reading).") #+sbcl (sb-ext:gc :full t)