aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJackson Ray Hamilton2019-04-07 13:25:57 -0700
committerJackson Ray Hamilton2019-04-08 22:48:24 -0700
commit98e36a3e31da10bf230743d285544305f730b60d (patch)
treefce1ee516b743e55f21fc28d6c29771e7c91f107
parent7b2e3c60d081597adb7feaaabfee8cb8de62289b (diff)
downloademacs-98e36a3e31da10bf230743d285544305f730b60d.tar.gz
emacs-98e36a3e31da10bf230743d285544305f730b60d.zip
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.
-rw-r--r--lisp/progmodes/js.el22
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."
1976(defun js-jsx--enclosing-tag-pos () 1976(defun js-jsx--enclosing-tag-pos ()
1977 "Return beginning and end of a JSXElement about point. 1977 "Return beginning and end of a JSXElement about point.
1978Look backward for a JSXElement that both starts before point and 1978Look backward for a JSXElement that both starts before point and
1979also ends after point. That may be either a self-closing 1979also ends at/after point. That may be either a self-closing
1980JSXElement or a JSXOpeningElement/JSXClosingElement pair." 1980JSXElement or a JSXOpeningElement/JSXClosingElement pair."
1981 (let ((start (point)) tag-beg tag-beg-pos tag-end-pos close-tag-pos) 1981 (let ((start (point)) tag-beg tag-beg-pos tag-end-pos close-tag-pos)
1982 (while 1982 (while
@@ -1991,9 +1991,21 @@ JSXElement or a JSXOpeningElement/JSXClosingElement pair."
1991 (< start tag-end-pos)) 1991 (< start tag-end-pos))
1992 (and (eq (car tag-beg) 'open) 1992 (and (eq (car tag-beg) 'open)
1993 (or (< start tag-end-pos) 1993 (or (< start tag-end-pos)
1994 (save-excursion 1994 (progn
1995 (goto-char tag-end-pos) 1995 (unless
1996 (setq close-tag-pos (js-jsx--matching-close-tag-pos)) 1996 ;; Try to read a cached close position,
1997 ;; but it might not be available yet.
1998 (setq close-tag-pos
1999 (get-text-property (point) 'js-jsx-close-tag-pos))
2000 (save-excursion
2001 (goto-char tag-end-pos)
2002 (setq close-tag-pos (js-jsx--matching-close-tag-pos)))
2003 (when close-tag-pos
2004 ;; Cache the close position to make future
2005 ;; searches faster.
2006 (put-text-property
2007 (point) (1+ (point))
2008 'js-jsx-close-tag-pos close-tag-pos)))
1997 ;; The JSXOpeningElement may be unclosed, else 2009 ;; The JSXOpeningElement may be unclosed, else
1998 ;; the closure must occur at/after the start 2010 ;; the closure must occur at/after the start
1999 ;; point (otherwise, a miscellaneous previous 2011 ;; point (otherwise, a miscellaneous previous
@@ -2179,7 +2191,7 @@ testing for syntax only valid as JSX."
2179 2191
2180(defconst js-jsx--text-properties 2192(defconst js-jsx--text-properties
2181 (list 2193 (list
2182 'js-jsx-tag-beg nil 'js-jsx-tag-end nil 2194 'js-jsx-tag-beg nil 'js-jsx-tag-end nil 'js-jsx-close-tag-pos nil
2183 'js-jsx-tag-name nil 'js-jsx-attribute-name nil 2195 'js-jsx-tag-name nil 'js-jsx-attribute-name nil
2184 'js-jsx-text nil 'js-jsx-expr nil 'js-jsx-expr-attribute nil) 2196 'js-jsx-text nil 'js-jsx-expr nil 'js-jsx-expr-attribute nil)
2185 "Plist of text properties added by `js-syntax-propertize'.") 2197 "Plist of text properties added by `js-syntax-propertize'.")