From: Stavros M. <mac...@us...> - 2007-05-22 16:47:28
|
Update of /cvsroot/maxima/maxima/share/contrib/numericalio In directory sc8-pr-cvs16.sourceforge.net:/tmp/cvs-serv29769 Modified Files: numericalio.lisp Log Message: Use a linear (not n^2) accumulation method in read_list Index: numericalio.lisp =================================================================== RCS file: /cvsroot/maxima/maxima/share/contrib/numericalio/numericalio.lisp,v retrieving revision 1.12 retrieving revision 1.13 diff -u -d -r1.12 -r1.13 --- numericalio.lisp 18 Feb 2007 01:20:35 -0000 1.12 +++ numericalio.lisp 22 May 2007 16:47:24 -0000 1.13 @@ -75,14 +75,16 @@ (let ((A '()) (L)) (setq file-name (require-string file-name)) (with-open-file (in file-name :if-does-not-exist nil) - (cond ((not (null in)) - (let ((sep-ch (get-input-sep-ch sep-ch-flag file-name))) - (loop - (setq L (read-line in nil 'eof)) - (if (eq L 'eof) (return (cons '(mlist simp) A))) - (setq A (append A (cdr (make-mlist-from-string L sep-ch))))))) - (t (merror "read_list: ~S: no such file" file-name)))))) - + (cond + ((not (null in)) + (let ((sep-ch (get-input-sep-ch sep-ch-flag file-name))) + (loop + (setq L (read-line in nil 'eof)) + (if (eq L 'eof) + (return (cons '(mlist simp) (nreverse A)))) + ;; use nreconc accumulation to avoid n^2 cons's + (setq A (nreconc (cdr (make-mlist-from-string L sep-ch)) A))))) + (t (merror "read_list: ~S: no such file" file-name)))))) ;; Usage: (make-mlist-from-string "1 2 3 foo bar baz") |