Skip to content

Commit 5b8a904

Browse files
authored
perf: replace --first in lsp--string-match-any with an explicit loop (#5011)
This avoids allocating intermediate lambdas. Also use string-match-p instead of string-match as no match data needs to be modified.
1 parent 4e23b03 commit 5b8a904

File tree

1 file changed

+14
-9
lines changed

1 file changed

+14
-9
lines changed

lsp-mode.el

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2017,15 +2017,20 @@ Used to prevent repeated warnings for the same invalid pattern.")
20172017
"Return the first regex, if any, within REGEX-LIST matching STR.
20182018
Returns the matching regex string on success, nil on no match or invalid regex.
20192019
Invalid regex patterns are logged as warnings (once per pattern) and skipped."
2020-
(--first (condition-case err
2021-
(string-match it str)
2022-
(invalid-regexp
2023-
(unless (gethash it lsp--warned-invalid-regexps)
2024-
(puthash it t lsp--warned-invalid-regexps)
2025-
(lsp-warn "Invalid regexp in watch pattern: %s (parsing %s)"
2026-
(error-message-string err) it))
2027-
nil))
2028-
regex-list))
2020+
(let (result)
2021+
(while regex-list
2022+
(let ((re (car regex-list)))
2023+
(setq regex-list (cdr regex-list))
2024+
(condition-case err
2025+
(when (string-match-p re str)
2026+
(setq result re
2027+
regex-list nil))
2028+
(invalid-regexp
2029+
(unless (gethash re lsp--warned-invalid-regexps)
2030+
(puthash re t lsp--warned-invalid-regexps)
2031+
(lsp-warn "Invalid regexp in watch pattern: %s (parsing %s)"
2032+
(error-message-string err) re))))))
2033+
result))
20292034

20302035
(cl-defstruct lsp-watch
20312036
(descriptors (make-hash-table :test 'equal))

0 commit comments

Comments
 (0)