Hello all--

After the talk on optimization this weekend, I
took a look at read-line.  The following code
offered (on my Pentium II anyway) a 20% speedup
for the trim (common) and split case.  It didn't
hurt (that I could measure) the performance of
the concat case and I've no idea how to test
the peek case (apologies for the formatting).

(define (new-read-line2 . args)
  (let ((port (if (null? args) (current-input-port) (car args)))
(handle-delim (if (eq? (length args) 1) 'trim (cadr args))))
(case handle-delim
((trim) (car (%read-line port)))
((split) (%read-line port))
(else
(let* ((data (%read-line port))
(line (car data))
(delim (cdr data)))
(case handle-delim
((concat) (if (and (string? line) (char? delim))
(string-append line (string delim))
line))
((peek) (if (char? delim) (unread-char delim port) line))
(else (error "unexpected handle-delim value: " handle-delim))))))))


--== Sent via Deja.com http://www.deja.com/ ==--
Before you buy.

Reply via email to