~solene/cl-yag

5e3abb608d7259d1c4acdd5be13a711fe4b49160 — Solene Rapenne 5 years ago 5c2a1c9
Improve performance by using proper functions to write string to file
1 files changed, 5 insertions(+), 9 deletions(-)

M generator.lisp
M generator.lisp => generator.lisp +5 -9
@@ 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)