From dcfa70bbdc04e0571e94b99f1a2c8e1ae3237f03 Mon Sep 17 00:00:00 2001 From: =?utf8?q?David=20V=C3=A1zquez?= Date: Tue, 4 Jun 2013 03:19:49 +0100 Subject: [PATCH] Speed up arrays concatenating a litte bit --- src/boot.lisp | 5 +---- src/compat.lisp | 3 --- src/compiler.lisp | 8 +++++++- src/sequence.lisp | 3 +++ src/string.lisp | 17 +++-------------- 5 files changed, 14 insertions(+), 22 deletions(-) diff --git a/src/boot.lisp b/src/boot.lisp index dc9b45f..59b97a0 100644 --- a/src/boot.lisp +++ b/src/boot.lisp @@ -87,7 +87,7 @@ (defvar *gensym-counter* 0) (defun gensym (&optional (prefix "G")) (setq *gensym-counter* (+ *gensym-counter* 1)) - (make-symbol (concat-two prefix (integer-to-string *gensym-counter*)))) + (make-symbol (concat prefix (integer-to-string *gensym-counter*)))) (defun boundp (x) (boundp x)) @@ -333,9 +333,6 @@ ((listp seq) (list-length seq)))) -(defun concat-two (s1 s2) - (concat-two s1 s2)) - (defmacro with-collect (&body body) (let ((head (gensym)) (tail (gensym))) diff --git a/src/compat.lisp b/src/compat.lisp index a11aa5d..3eaf4ff 100644 --- a/src/compat.lisp +++ b/src/compat.lisp @@ -38,9 +38,6 @@ `(eval-when (:compile-toplevel :load-toplevel :execute) ,@body)) -(defun concat-two (s1 s2) - (concatenate 'string s1 s2)) - (defun aset (array idx value) (setf (aref array idx) value)) diff --git a/src/compiler.lisp b/src/compiler.lisp index 1fb6305..449bb3e 100644 --- a/src/compiler.lisp +++ b/src/compiler.lisp @@ -1309,7 +1309,13 @@ "if (i < 0 || i >= x.length) throw 'Out of range';" *newline* "return x[i] = " value ";" *newline*)) - +(define-builtin concatenate-storage-vector (sv1 sv2) + (js!selfcall + "var sv1 = " sv1 ";" *newline* + "var r = sv1.concat(" sv2 ");" *newline* + "r.type = sv1.type;" *newline* + "r.stringp = sv1.stringp;" *newline* + "return r;" *newline*)) (define-builtin get-internal-real-time () "(new Date()).getTime()") diff --git a/src/sequence.lisp b/src/sequence.lisp index 7e96df0..85d5276 100644 --- a/src/sequence.lisp +++ b/src/sequence.lisp @@ -152,3 +152,6 @@ ((= j b) new) (aset new i (aref seq j))))) (t (not-seq-error seq)))) + + + diff --git a/src/string.lisp b/src/string.lisp index 7026cb3..411c638 100644 --- a/src/string.lisp +++ b/src/string.lisp @@ -62,21 +62,10 @@ `(char ,g!string ,g!index)))) -(defun concat-two (string1 string2) - (let* ((len1 (length string1)) - (len2 (length string2)) - (string (make-array (+ len1 len2) :element-type 'character)) - (i 0)) - (dotimes (j len1) - (aset string i (char string1 j)) - (incf i)) - (dotimes (j len2) - (aset string i (char string2 j)) - (incf i)) - string)) - (defun concat (&rest strs) - (!reduce #'concat-two strs "")) + (flet ((concat-two (str1 str2) + (concatenate-storage-vector str1 str2))) + (!reduce #'concat-two strs ""))) (defun string-upcase (string) -- 1.7.10.4