Re: Is this too inefficient?

From: Ken Anderson <>
Date: Sat, 13 Jan 1996 17:12:58 +0000

>For an n-line file this does n mallocs each of which is an average of
>half the length of the file, and the number of characters copied in
>calls to string-append is half the square of the length of the file.
>Does this seem unreasonably inefficient to anyone else out there?
A recent C++ Report article by Andrew Koenig (Jan 96 i think) on C++
performance uses something like this bug as an example. His solution is
similar to Lars':
  (define (port->string p)
    (unless (or (input-port? p) (input-string-port? p))
       (error "port->string: Bad port ~S" p))
    ;; Read all the lines of port and put them in a string
    (let loop ((res '()))
      (let ((line (read-line p))) ; aesthetic change only
        (if (eof-object? line)
            (apply string-append (reverse! res))
            (loop (cons "\n" (cons line res)))))))
Received on Sun Jan 14 1996 - 02:18:48 CET

This archive was generated by hypermail 2.3.0 : Mon Jul 21 2014 - 19:38:59 CEST