branch: externals/xr
commit b07de9bc2cc5c33e782b6c3d743eaf42ed71e570
Author: Mattias EngdegÄrd <matti...@acm.org>
Commit: Mattias EngdegÄrd <matti...@acm.org>

    Faster joining of chars to strings
---
 xr.el | 35 +++++++++++++++++++++++++----------
 1 file changed, 25 insertions(+), 10 deletions(-)

diff --git a/xr.el b/xr.el
index e1843a941f..5996c40839 100644
--- a/xr.el
+++ b/xr.el
@@ -277,19 +277,34 @@
 (defun xr--rev-join-seq (sequence)
   "Reverse SEQUENCE, flatten any (seq ...) inside, and concatenate
 adjacent strings. SEQUENCE is used destructively."
-  (let ((result nil))
+  (let ((strings nil)
+        (result nil))
     (while sequence
       (let ((elem (car sequence))
             (rest (cdr sequence)))
-        (cond ((and (consp elem) (eq (car elem) 'seq))
-               (setq sequence (nconc (nreverse (cdr elem)) rest)))
-              ((and (stringp elem) (stringp (car result)))
-               (setq result (cons (concat elem (car result)) (cdr result)))
-               (setq sequence rest))
-              (t
-               (setq result (cons elem result))
-               (setq sequence rest)))))
-    result))
+        (setq sequence
+              (cond ((stringp elem)
+                     (push elem strings)
+                     rest)
+                    ((eq (car-safe elem) 'seq)
+                     (nconc (nreverse (cdr elem)) rest))
+                    (strings
+                     (push (if (cdr strings)
+                               (mapconcat #'identity strings nil)
+                             (car strings))
+                           result)
+                     (setq strings nil)
+                     (push elem result)
+                     rest)
+                    (t
+                     (push elem result)
+                     rest)))))
+    (if strings
+        (cons (if (cdr strings)
+                  (mapconcat #'identity strings nil)
+                (car strings))
+              result)
+      result)))
 
 (defun xr--char-category (negated category-code)
   (let* ((sym (assq category-code

Reply via email to