From: Vladimir Sedach Date: Sat, 4 Apr 2009 22:39:15 +0000 (-0600) Subject: Removed compile-time constant string concatenation from the Parenscript printer,... X-Git-Url: http://git.hcoop.net/clinton/parenscript.git/commitdiff_plain/496ef8be52f3e6c22ffdb72a36b4fdc0ed3cd93f Removed compile-time constant string concatenation from the Parenscript printer, which was significantly slowing down compilation. --- diff --git a/docs/reference.lisp b/docs/reference.lisp index c7fb69f..8ead719 100644 --- a/docs/reference.lisp +++ b/docs/reference.lisp @@ -1084,7 +1084,7 @@ a-variable => aVariable (document.write (ps-html ((:a :href "#" :onclick (ps-inline (transport))) "link"))) -=> document.write('link') +=> document.write('link') ;;; Forms may be used in attribute lists to conditionally generate ;;; the next attribute. In this example the textarea is sometimes disabled. diff --git a/src/printer.lisp b/src/printer.lisp index 7d3fae8..c4ce792 100644 --- a/src/printer.lisp +++ b/src/printer.lisp @@ -1,4 +1,4 @@ -(in-package :parenscript) +(in-package "PARENSCRIPT") (defvar *ps-print-pretty* t) (defvar *indent-num-spaces* 4) @@ -15,16 +15,11 @@ vice-versa.") (defmethod parenscript-print (form) (let ((*indent-level* 0) (*print-accumulator* ())) - (if (and (listp form) (eql 'js-block (car form))) ; ignore top-level block - (loop for (statement . remaining) on (third form) do - (ps-print statement) (psw ";") (when remaining (psw #\Newline))) - (ps-print form)) - (reduce (lambda (acc next-token) - (if (and (stringp next-token) - (stringp (car (last acc)))) - (append (butlast acc) (list (concatenate 'string (car (last acc)) next-token))) - (append acc (list next-token)))) - (cons () (reverse *print-accumulator*))))) + (if (and (listp form) (eql 'js-block (car form))) ; ignore top-level block + (loop for (statement . remaining) on (third form) do + (ps-print statement) (psw ";") (when remaining (psw #\Newline))) + (ps-print form)) + (nreverse *print-accumulator*))) (defun psw (obj) (push (if (characterp obj) (string obj) obj) *print-accumulator*)) @@ -55,10 +50,8 @@ arguments, defines a printer for that form using the given body." (defun newline-and-indent () (if *ps-print-pretty* - (when (and (stringp (car *print-accumulator*)) - (not (char= #\Newline (char (car *print-accumulator*) (1- (length (car *print-accumulator*)))))) - (psw #\Newline)) - (loop repeat (* *indent-level* *indent-num-spaces*) do (psw #\Space))) + (progn (psw #\Newline) + (loop repeat (* *indent-level* *indent-num-spaces*) do (psw #\Space))) (psw #\Space))) (defparameter *js-lisp-escaped-chars* diff --git a/t/ps-tests.lisp b/t/ps-tests.lisp index b493903..d1779e9 100644 --- a/t/ps-tests.lisp +++ b/t/ps-tests.lisp @@ -476,7 +476,7 @@ __setf_someThing(_js2, _js3, _js4);") :onclick (ps-inline (transport))) img)) img)) - "document.write(LINKORNOT == 1 ? '' + img + '' : img)") + "document.write(LINKORNOT == 1 ? '' + img + '' : img)") (test-ps-js negate-number-literal ;; ok, this was broken and fixed before, but no one bothered to add the test! (- 1) diff --git a/t/reference-tests.lisp b/t/reference-tests.lisp index 11c36f2..3460390 100644 --- a/t/reference-tests.lisp +++ b/t/reference-tests.lisp @@ -593,7 +593,7 @@ for (var k in obj) { (document.write (ps-html ((:a :href "#" :onclick (ps-inline (transport))) "link"))) - "document.write('link')") + "document.write('link')") (test-ps-js the-html-generator-4 (let* ((disabled nil)