emacs-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Emacs-diffs] master 8e2e252: Cache results of `css--property-values'


From: Simen Heggestøyl
Subject: [Emacs-diffs] master 8e2e252: Cache results of `css--property-values'
Date: Sun, 24 Apr 2016 13:03:17 +0000

branch: master
commit 8e2e252932faf3320f72a0b62136c4606e09ebc3
Author: Simen Heggestøyl <address@hidden>
Commit: Simen Heggestøyl <address@hidden>

    Cache results of `css--property-values'
    
    * lisp/textmodes/css-mode.el (css--property-values): Cache computed
    values.
    
    * test/lisp/textmodes/css-mode-tests.el (css-test-property-value-cache):
    New regression test for the above.
---
 lisp/textmodes/css-mode.el            |   16 +++++++++-------
 test/lisp/textmodes/css-mode-tests.el |    7 +++++++
 2 files changed, 16 insertions(+), 7 deletions(-)

diff --git a/lisp/textmodes/css-mode.el b/lisp/textmodes/css-mode.el
index 2a61fe3..8a4daac 100644
--- a/lisp/textmodes/css-mode.el
+++ b/lisp/textmodes/css-mode.el
@@ -792,13 +792,15 @@ the symbol VALUE-CLASS."
 Completion candidates are looked up in `css-property-alist' by
 the string PROPERTY."
   (or (gethash property css--property-value-cache)
-      (seq-mapcat
-       (lambda (value)
-         (if (stringp value)
-             (list value)
-           (or (css--value-class-lookup value)
-               (css--property-values (symbol-name value)))))
-       (cdr (assoc property css-property-alist)))))
+      (let ((values
+             (seq-mapcat
+              (lambda (value)
+                (if (stringp value)
+                    (list value)
+                  (or (css--value-class-lookup value)
+                      (css--property-values (symbol-name value)))))
+              (cdr (assoc property css-property-alist)))))
+        (puthash property values css--property-value-cache))))
 
 (defun css--complete-property-value ()
   "Complete property value at point."
diff --git a/test/lisp/textmodes/css-mode-tests.el 
b/test/lisp/textmodes/css-mode-tests.el
index 9c5953d..805364c 100644
--- a/test/lisp/textmodes/css-mode-tests.el
+++ b/test/lisp/textmodes/css-mode-tests.el
@@ -57,6 +57,13 @@
   ;; because it refers to the value class of the same name.
   (should (= (length (css--property-values "color")) 18)))
 
+(ert-deftest css-test-property-value-cache ()
+  "Test that `css--property-value-cache' is in use."
+  (should-not (gethash "word-wrap" css--property-value-cache))
+  (let ((word-wrap-values (css--property-values "word-wrap")))
+    (should (equal (gethash "word-wrap" css--property-value-cache)
+                   word-wrap-values))))
+
 (ert-deftest css-test-value-class-lookup ()
   (should
    (equal (sort (css--value-class-lookup 'position) #'string-lessp)



reply via email to

[Prev in Thread] Current Thread [Next in Thread]