Save some space in WITH-OUTPUT-TO-STRING.
authorStas Boukarev <stassats@gmail.com>
Fri, 6 Sep 2013 14:23:40 +0000 (18:23 +0400)
committerStas Boukarev <stassats@gmail.com>
Fri, 6 Sep 2013 14:23:40 +0000 (18:23 +0400)
Not passing :element-type 'character to MAKE-STRING-OUTPUT-STREAM
saves a few bytes, since it's the default value.

src/code/macros.lisp

index 3bfcbaa..3cbc7af 100644 (file)
@@ -471,17 +471,21 @@ invoked. In that case it will store into PLACE and start over."
                  ;; (see FILL-POINTER-OUTPUT-STREAM FIXME in stream.lisp),
                  ;; but it still has to be evaluated for side-effects.
                  (,element-type-var ,element-type))
-            (declare (ignore ,element-type-var))
-            ,@decls
-            (unwind-protect
-                 (progn ,@forms)
-              (close ,var))))
-      `(let ((,var (make-string-output-stream :element-type ,element-type)))
-         ,@decls
-         (unwind-protect
-             (progn ,@forms)
-           (close ,var))
-         (get-output-stream-string ,var)))))
+             (declare (ignore ,element-type-var))
+             ,@decls
+             (unwind-protect
+                  (progn ,@forms)
+               (close ,var))))
+        `(let ((,var (make-string-output-stream
+                      ;; CHARACTER is the default element-type of
+                      ;; string-ouput-stream, save a few bytes when passing it
+                      ,@(and (not (equal element-type ''character))
+                             `(:element-type ,element-type)))))
+           ,@decls
+           (unwind-protect
+                (progn ,@forms)
+             (close ,var))
+           (get-output-stream-string ,var)))))
 \f
 ;;;; miscellaneous macros