commit 5e3abb608d7259d1c4acdd5be13a711fe4b49160 Solene Rapenne <solene@perso.pw> 2019-08-27 09:07:18 +0200 Improve performance by using proper functions to write string to file
generator.lisp | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-)
diff --git a/generator.lisp b/generator.lisp index 26c4829..ca01c36 100644 --- a/generator.lisp +++ b/generator.lisp @@ -100,14 +100,10 @@ ;; we escape ~ to avoid failures with format (defun load-file(path) (if (probe-file path) - (replace-all - (apply #'concatenate 'string - (with-open-file (stream path) - (loop for line = (read-line stream nil) - while line - collect - (format nil "~a~%" line)))) - "~" "~~") + (with-open-file (stream path) + (let ((contents (make-string (file-length stream)))) + (read-sequence contents stream) + contents)) (progn (format t "ERROR : file ~a not found. Aborting~%" path) (quit)))) @@ -115,7 +111,7 @@ ;; save a string in a file (defun save-file(path data) (with-open-file (stream path :direction :output :if-exists :supersede) - (format stream data))) + (write-sequence data stream))) ;; simplify the str replace work (defmacro template(before &body after)