diff options
| author | Simen Heggestøyl | 2016-04-24 11:03:22 +0200 |
|---|---|---|
| committer | Simen Heggestøyl | 2016-04-24 15:02:05 +0200 |
| commit | 8e2e252932faf3320f72a0b62136c4606e09ebc3 (patch) | |
| tree | aaaaa5b71b2b8ac3fbfc6b27985f1b07c71ce43c | |
| parent | 5cb7620027f78a3a0f473972a0584c8ea1791398 (diff) | |
| download | emacs-8e2e252932faf3320f72a0b62136c4606e09ebc3.tar.gz emacs-8e2e252932faf3320f72a0b62136c4606e09ebc3.zip | |
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.
| -rw-r--r-- | lisp/textmodes/css-mode.el | 16 | ||||
| -rw-r--r-- | 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 2a61fe3736b..8a4daac353a 100644 --- a/lisp/textmodes/css-mode.el +++ b/lisp/textmodes/css-mode.el | |||
| @@ -792,13 +792,15 @@ the symbol VALUE-CLASS." | |||
| 792 | Completion candidates are looked up in `css-property-alist' by | 792 | Completion candidates are looked up in `css-property-alist' by |
| 793 | the string PROPERTY." | 793 | the string PROPERTY." |
| 794 | (or (gethash property css--property-value-cache) | 794 | (or (gethash property css--property-value-cache) |
| 795 | (seq-mapcat | 795 | (let ((values |
| 796 | (lambda (value) | 796 | (seq-mapcat |
| 797 | (if (stringp value) | 797 | (lambda (value) |
| 798 | (list value) | 798 | (if (stringp value) |
| 799 | (or (css--value-class-lookup value) | 799 | (list value) |
| 800 | (css--property-values (symbol-name value))))) | 800 | (or (css--value-class-lookup value) |
| 801 | (cdr (assoc property css-property-alist))))) | 801 | (css--property-values (symbol-name value))))) |
| 802 | (cdr (assoc property css-property-alist))))) | ||
| 803 | (puthash property values css--property-value-cache)))) | ||
| 802 | 804 | ||
| 803 | (defun css--complete-property-value () | 805 | (defun css--complete-property-value () |
| 804 | "Complete property value at point." | 806 | "Complete property value at point." |
diff --git a/test/lisp/textmodes/css-mode-tests.el b/test/lisp/textmodes/css-mode-tests.el index 9c5953db4a8..805364c9f42 100644 --- a/test/lisp/textmodes/css-mode-tests.el +++ b/test/lisp/textmodes/css-mode-tests.el | |||
| @@ -57,6 +57,13 @@ | |||
| 57 | ;; because it refers to the value class of the same name. | 57 | ;; because it refers to the value class of the same name. |
| 58 | (should (= (length (css--property-values "color")) 18))) | 58 | (should (= (length (css--property-values "color")) 18))) |
| 59 | 59 | ||
| 60 | (ert-deftest css-test-property-value-cache () | ||
| 61 | "Test that `css--property-value-cache' is in use." | ||
| 62 | (should-not (gethash "word-wrap" css--property-value-cache)) | ||
| 63 | (let ((word-wrap-values (css--property-values "word-wrap"))) | ||
| 64 | (should (equal (gethash "word-wrap" css--property-value-cache) | ||
| 65 | word-wrap-values)))) | ||
| 66 | |||
| 60 | (ert-deftest css-test-value-class-lookup () | 67 | (ert-deftest css-test-value-class-lookup () |
| 61 | (should | 68 | (should |
| 62 | (equal (sort (css--value-class-lookup 'position) #'string-lessp) | 69 | (equal (sort (css--value-class-lookup 'position) #'string-lessp) |