]> git.eshelyaron.com Git - emacs.git/commitdiff
Cache results of `css--property-values'
authorSimen Heggestøyl <simenheg@gmail.com>
Sun, 24 Apr 2016 09:03:22 +0000 (11:03 +0200)
committerSimen Heggestøyl <simenheg@gmail.com>
Sun, 24 Apr 2016 13:02:05 +0000 (15:02 +0200)
* 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
test/lisp/textmodes/css-mode-tests.el

index 2a61fe3736b968f0ec07f7a08c863a19466e200b..8a4daac353a15d61be9a47f578dd3912d7a4c183 100644 (file)
@@ -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."
index 9c5953db4a8014072e06fe069c08b155e6fae2b5..805364c9f4216e4212c4e2315716d5e95f6bdf7a 100644 (file)
   ;; 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)