branch: elpa/extmap
commit fb6630228d668bd1866f46557be16cbdcc00e8a6
Author: Paul Pogonyshev <pogonys...@gmail.com>
Commit: Paul Pogonyshev <pogonys...@gmail.com>

    Speed-optimize `extmap--equal-including-properties'; while not terribly 
important, 3 s vs. 29 in a real-world usecase is a good improvement.
---
 extmap.el           | 23 ++++++++++++++---------
 test/extmap-test.el |  3 +++
 2 files changed, 17 insertions(+), 9 deletions(-)

diff --git a/extmap.el b/extmap.el
index 57d66cb0bf..e2ec6c25de 100644
--- a/extmap.el
+++ b/extmap.el
@@ -497,15 +497,20 @@ Only available on Emacs 25, as this requires `generator' 
package."
                 (while (and at equal)
                   (let ((next (next-property-change at a)))
                     (setq equal (and (equal next (next-property-change at b))
-                                     (let ((a-properties    
(text-properties-at at a))
-                                           (b-properties    
(text-properties-at at b))
-                                           (a-property-hash (make-hash-table))
-                                           (b-property-hash (make-hash-table)))
-                                       (while a-properties
-                                         (puthash (pop a-properties) (pop 
a-properties) a-property-hash))
-                                       (while b-properties
-                                         (puthash (pop b-properties) (pop 
b-properties) b-property-hash))
-                                       (extmap--equal-including-properties 
a-property-hash b-property-hash)))
+                                     (let ((a-properties (text-properties-at 
at a))
+                                           (b-properties (text-properties-at 
at b)))
+                                       ;; Speedup, especially for plain 
strings: don't create
+                                       ;; hash-tables if there are no 
properties at all.
+                                       (or (and (null a-properties) (null 
b-properties))
+                                           (and a-properties b-properties
+                                                ;; Property keys are compared 
by `eq' everywhere.
+                                                (let ((a-property-hash 
(make-hash-table :test #'eq))
+                                                      (b-property-hash 
(make-hash-table :test #'eq)))
+                                                  (while a-properties
+                                                    (puthash (pop 
a-properties) (pop a-properties) a-property-hash))
+                                                  (while b-properties
+                                                    (puthash (pop 
b-properties) (pop b-properties) b-property-hash))
+                                                  
(extmap--equal-including-properties a-property-hash b-property-hash))))))
                           at    next)))
                 equal)))
         ((consp a)
diff --git a/test/extmap-test.el b/test/extmap-test.el
index b095ace324..872cc1b507 100644
--- a/test/extmap-test.el
+++ b/test/extmap-test.el
@@ -172,6 +172,9 @@
   (should-not (extmap--equal-including-properties '(1 2 3) '(1 2 "3")))
   (should-not (extmap--equal-including-properties '(1 2 3) '(1 2 3 4)))
   (should-not (extmap--equal-including-properties (propertize "foo" 'face 
'bold) "foo"))
+  (should-not (extmap--equal-including-properties (propertize "foo" 'face 
'bold) (propertize "foo" 'face 'italic)))
+  (should-not (extmap--equal-including-properties (propertize "foo" 'lol 
(vector (propertize "bar" 'face 'bold)))
+                                                  (propertize "foo" 'lol 
(vector (propertize "bar" 'face 'italic)))))
   (should (extmap--equal-including-properties nil nil))
   (should (extmap--equal-including-properties 1 1))
   (should (extmap--equal-including-properties (cons 'a 'b) (cons 'a 'b)))

Reply via email to