diff options
| author | Jackson Ray Hamilton <jackson@jacksonrayhamilton.com> | 2019-04-07 13:25:57 -0700 |
|---|---|---|
| committer | Jackson Ray Hamilton <jackson@jacksonrayhamilton.com> | 2019-04-08 22:48:24 -0700 |
| commit | 98e36a3e31da10bf230743d285544305f730b60d (patch) | |
| tree | fce1ee516b743e55f21fc28d6c29771e7c91f107 /lisp/progmodes/js.el | |
| parent | 7b2e3c60d081597adb7feaaabfee8cb8de62289b (diff) | |
| download | emacs-98e36a3e31da10bf230743d285544305f730b60d.tar.gz | |
Optimize js-jsx--enclosing-tag-pos
* lisp/progmodes/js.el (js-jsx--enclosing-tag-pos): Update docstring
to be more precise. Also, remember close tag positions after they’ve
been calculated once to avoid many redundant calls to
js-jsx--matching-close-tag-pos.
(js-jsx--text-properties): Ensure js-jsx-close-tag-pos text properties
get cleaned up, too.
Diffstat (limited to 'lisp/progmodes/js.el')
| -rw-r--r-- | lisp/progmodes/js.el | 22 |
1 files changed, 17 insertions, 5 deletions
diff --git a/lisp/progmodes/js.el b/lisp/progmodes/js.el index 694a79f0d97..21e6b683b78 100644 --- a/lisp/progmodes/js.el +++ b/lisp/progmodes/js.el @@ -1976,7 +1976,7 @@ the match. Return nil if a match can’t be found." (defun js-jsx--enclosing-tag-pos () "Return beginning and end of a JSXElement about point. Look backward for a JSXElement that both starts before point and -also ends after point. That may be either a self-closing +also ends at/after point. That may be either a self-closing JSXElement or a JSXOpeningElement/JSXClosingElement pair." (let ((start (point)) tag-beg tag-beg-pos tag-end-pos close-tag-pos) (while @@ -1991,9 +1991,21 @@ JSXElement or a JSXOpeningElement/JSXClosingElement pair." (< start tag-end-pos)) (and (eq (car tag-beg) 'open) (or (< start tag-end-pos) - (save-excursion - (goto-char tag-end-pos) - (setq close-tag-pos (js-jsx--matching-close-tag-pos)) + (progn + (unless + ;; Try to read a cached close position, + ;; but it might not be available yet. + (setq close-tag-pos + (get-text-property (point) 'js-jsx-close-tag-pos)) + (save-excursion + (goto-char tag-end-pos) + (setq close-tag-pos (js-jsx--matching-close-tag-pos))) + (when close-tag-pos + ;; Cache the close position to make future + ;; searches faster. + (put-text-property + (point) (1+ (point)) + 'js-jsx-close-tag-pos close-tag-pos))) ;; The JSXOpeningElement may be unclosed, else ;; the closure must occur at/after the start ;; point (otherwise, a miscellaneous previous @@ -2179,7 +2191,7 @@ testing for syntax only valid as JSX." (defconst js-jsx--text-properties (list - 'js-jsx-tag-beg nil 'js-jsx-tag-end nil + 'js-jsx-tag-beg nil 'js-jsx-tag-end nil 'js-jsx-close-tag-pos nil 'js-jsx-tag-name nil 'js-jsx-attribute-name nil 'js-jsx-text nil 'js-jsx-expr nil 'js-jsx-expr-attribute nil) "Plist of text properties added by `js-syntax-propertize'.") |
