diff options
| author | Alan Mackenzie | 2020-12-14 20:44:33 +0000 |
|---|---|---|
| committer | Alan Mackenzie | 2020-12-14 20:44:33 +0000 |
| commit | 071bfd9840b1048bdc4f2c461fe50bd33dc919e8 (patch) | |
| tree | 1bb3ce46c2038b6a3ccd41a99e7b9c36e0bad79e | |
| parent | 9022df70270243f211c54ccd66800320148b8434 (diff) | |
| download | emacs-071bfd9840b1048bdc4f2c461fe50bd33dc919e8.tar.gz emacs-071bfd9840b1048bdc4f2c461fe50bd33dc919e8.zip | |
Optimise c-font-lock-<>-arglists, particularly for buffers with few <..> pairs
* lisp/progmodes/cc-fonts.el (c-font-lock-<>-arglists): In place of a regexp
search for a complicated and slow regexp, search simply for "<" ouside of
literals together with add hoc testing of other requirements for a <...>
match.
* lisp/progmodes/cc-langs.el (c-nonsymbol-key): New c-lang-defvar from the
c-lang-const.
| -rw-r--r-- | lisp/progmodes/cc-fonts.el | 123 | ||||
| -rw-r--r-- | lisp/progmodes/cc-langs.el | 1 |
2 files changed, 67 insertions, 57 deletions
diff --git a/lisp/progmodes/cc-fonts.el b/lisp/progmodes/cc-fonts.el index bb7e5bea6e6..38166c27ec8 100644 --- a/lisp/progmodes/cc-fonts.el +++ b/lisp/progmodes/cc-fonts.el | |||
| @@ -1008,66 +1008,75 @@ casts and declarations are fontified. Used on level 2 and higher." | |||
| 1008 | (boundp 'parse-sexp-lookup-properties))) | 1008 | (boundp 'parse-sexp-lookup-properties))) |
| 1009 | (c-parse-and-markup-<>-arglists t) | 1009 | (c-parse-and-markup-<>-arglists t) |
| 1010 | c-restricted-<>-arglists | 1010 | c-restricted-<>-arglists |
| 1011 | id-start id-end id-face pos kwd-sym) | 1011 | id-start id-end id-face pos kwd-sym |
| 1012 | old-pos) | ||
| 1012 | 1013 | ||
| 1013 | (while (and (< (point) limit) | 1014 | (while (and (< (point) limit) |
| 1014 | (re-search-forward c-opt-<>-arglist-start limit t)) | 1015 | (setq old-pos (point)) |
| 1015 | 1016 | (c-syntactic-re-search-forward "<" limit t nil t)) | |
| 1016 | (setq id-start (match-beginning 1) | 1017 | (setq pos (point)) |
| 1017 | id-end (match-end 1) | 1018 | (save-excursion |
| 1018 | pos (point)) | 1019 | (backward-char) |
| 1019 | 1020 | (c-backward-syntactic-ws old-pos) | |
| 1020 | (goto-char id-start) | 1021 | (if (re-search-backward |
| 1021 | (unless (c-skip-comments-and-strings limit) | 1022 | (concat "\\(\\`\\|" c-nonsymbol-key "\\)\\(" c-symbol-key"\\)\\=") |
| 1022 | (setq kwd-sym nil | 1023 | old-pos t) |
| 1023 | c-restricted-<>-arglists nil | 1024 | (setq id-start (match-beginning 2) |
| 1024 | id-face (get-text-property id-start 'face)) | 1025 | id-end (match-end 2)) |
| 1025 | 1026 | (setq id-start nil id-end nil))) | |
| 1026 | (if (cond | 1027 | |
| 1027 | ((eq id-face 'font-lock-type-face) | 1028 | (when id-start |
| 1028 | ;; The identifier got the type face so it has already been | 1029 | (goto-char id-start) |
| 1029 | ;; handled in `c-font-lock-declarations'. | 1030 | (unless (c-skip-comments-and-strings limit) |
| 1030 | nil) | 1031 | (setq kwd-sym nil |
| 1031 | 1032 | c-restricted-<>-arglists nil | |
| 1032 | ((eq id-face 'font-lock-keyword-face) | 1033 | id-face (get-text-property id-start 'face)) |
| 1033 | (when (looking-at c-opt-<>-sexp-key) | 1034 | |
| 1034 | ;; There's a special keyword before the "<" that tells | 1035 | (if (cond |
| 1035 | ;; that it's an angle bracket arglist. | 1036 | ((eq id-face 'font-lock-type-face) |
| 1036 | (setq kwd-sym (c-keyword-sym (match-string 1))))) | 1037 | ;; The identifier got the type face so it has already been |
| 1037 | 1038 | ;; handled in `c-font-lock-declarations'. | |
| 1038 | (t | 1039 | nil) |
| 1039 | ;; There's a normal identifier before the "<". If we're not in | ||
| 1040 | ;; a declaration context then we set `c-restricted-<>-arglists' | ||
| 1041 | ;; to avoid recognizing templates in function calls like "foo (a | ||
| 1042 | ;; < b, c > d)". | ||
| 1043 | (c-backward-syntactic-ws) | ||
| 1044 | (when (and (memq (char-before) '(?\( ?,)) | ||
| 1045 | (not (eq (get-text-property (1- (point)) 'c-type) | ||
| 1046 | 'c-decl-arg-start))) | ||
| 1047 | (setq c-restricted-<>-arglists t)) | ||
| 1048 | t)) | ||
| 1049 | 1040 | ||
| 1050 | (progn | 1041 | ((eq id-face 'font-lock-keyword-face) |
| 1051 | (goto-char (1- pos)) | 1042 | (when (looking-at c-opt-<>-sexp-key) |
| 1052 | ;; Check for comment/string both at the identifier and | 1043 | ;; There's a special keyword before the "<" that tells |
| 1053 | ;; at the "<". | 1044 | ;; that it's an angle bracket arglist. |
| 1054 | (unless (c-skip-comments-and-strings limit) | 1045 | (setq kwd-sym (c-keyword-sym (match-string 2))))) |
| 1055 | 1046 | ||
| 1056 | (c-fontify-types-and-refs () | 1047 | (t |
| 1057 | (when (c-forward-<>-arglist (c-keyword-member | 1048 | ;; There's a normal identifier before the "<". If we're not in |
| 1058 | kwd-sym 'c-<>-type-kwds)) | 1049 | ;; a declaration context then we set `c-restricted-<>-arglists' |
| 1059 | (when (and c-opt-identifier-concat-key | 1050 | ;; to avoid recognizing templates in function calls like "foo (a |
| 1060 | (not (get-text-property id-start 'face))) | 1051 | ;; < b, c > d)". |
| 1061 | (c-forward-syntactic-ws) | 1052 | (c-backward-syntactic-ws) |
| 1062 | (cond ((looking-at c-opt-identifier-concat-key) | 1053 | (when (and (memq (char-before) '(?\( ?,)) |
| 1063 | (c-put-font-lock-face id-start id-end | 1054 | (not (eq (get-text-property (1- (point)) 'c-type) |
| 1064 | c-reference-face-name)) | 1055 | 'c-decl-arg-start))) |
| 1065 | ((eq (char-after) ?\()) | 1056 | (setq c-restricted-<>-arglists t)) |
| 1066 | (t (c-put-font-lock-face id-start id-end | 1057 | t)) |
| 1067 | 'font-lock-type-face)))))) | 1058 | |
| 1068 | 1059 | (progn | |
| 1069 | (goto-char pos))) | 1060 | (goto-char (1- pos)) |
| 1070 | (goto-char pos)))))) | 1061 | ;; Check for comment/string both at the identifier and |
| 1062 | ;; at the "<". | ||
| 1063 | (unless (c-skip-comments-and-strings limit) | ||
| 1064 | |||
| 1065 | (c-fontify-types-and-refs () | ||
| 1066 | (when (c-forward-<>-arglist (c-keyword-member | ||
| 1067 | kwd-sym 'c-<>-type-kwds)) | ||
| 1068 | (when (and c-opt-identifier-concat-key | ||
| 1069 | (not (get-text-property id-start 'face))) | ||
| 1070 | (c-forward-syntactic-ws) | ||
| 1071 | (cond ((looking-at c-opt-identifier-concat-key) | ||
| 1072 | (c-put-font-lock-face id-start id-end | ||
| 1073 | c-reference-face-name)) | ||
| 1074 | ((eq (char-after) ?\()) | ||
| 1075 | (t (c-put-font-lock-face id-start id-end | ||
| 1076 | 'font-lock-type-face)))))) | ||
| 1077 | |||
| 1078 | (goto-char pos))) | ||
| 1079 | (goto-char pos))))))) | ||
| 1071 | nil) | 1080 | nil) |
| 1072 | 1081 | ||
| 1073 | (defun c-font-lock-declarators (limit list types not-top | 1082 | (defun c-font-lock-declarators (limit list types not-top |
diff --git a/lisp/progmodes/cc-langs.el b/lisp/progmodes/cc-langs.el index d6089ea2950..4d1aeaa5cb9 100644 --- a/lisp/progmodes/cc-langs.el +++ b/lisp/progmodes/cc-langs.el | |||
| @@ -699,6 +699,7 @@ It's assumed to not contain any submatchers." | |||
| 699 | ;; The same thing regarding Unicode identifiers applies here as to | 699 | ;; The same thing regarding Unicode identifiers applies here as to |
| 700 | ;; `c-symbol-key'. | 700 | ;; `c-symbol-key'. |
| 701 | t (concat "[" (c-lang-const c-nonsymbol-chars) "]")) | 701 | t (concat "[" (c-lang-const c-nonsymbol-chars) "]")) |
| 702 | (c-lang-defvar c-nonsymbol-key (c-lang-const c-nonsymbol-key)) | ||
| 702 | 703 | ||
| 703 | (c-lang-defconst c-identifier-ops | 704 | (c-lang-defconst c-identifier-ops |
| 704 | "The operators that make up fully qualified identifiers. nil in | 705 | "The operators that make up fully qualified identifiers. nil in |