I'm tracking down inefficiencies in a program I'm writing, and
I came across this code in init.stk:
(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 "") (line (read-line p)))
(if (eof-object? line)
res
(loop (string-append res line "\n") (read-line p)))))
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?
What may be needed is some more sophisticated string processing
functions, or string objects that can share storage, not null
terminated. Eh?
Received on Wed Dec 20 1995 - 00:42:29 CET
This archive was generated by hypermail 2.3.0
: Mon Jul 21 2014 - 19:38:59 CEST