branch: elpa/swift-mode commit b3af0b0106ababd5e4190eb0cc4af7e34c95c459 Author: ap4y <l...@pisem.net> Commit: ap4y <l...@pisem.net>
Constraint all look backs to the reasonable amount of lines `looking-back` is notoriously slow and can reduce performance of the lexer. In most cases this operations can be naturally constrained to a several chars. But several lexer rules require deeper search, in this case we can constraint such operations by a `line-beginning-position`. --- swift-mode.el | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/swift-mode.el b/swift-mode.el index b45391c..561a00b 100644 --- a/swift-mode.el +++ b/swift-mode.el @@ -257,14 +257,14 @@ ";") ((looking-at "{") (forward-char 1) - (if (looking-back "\\(class\\|protocol\\) [^{]+{") + (if (looking-back "\\(class\\|protocol\\) [^{]+{" (line-beginning-position) t) (concat (match-string 1) "-{") "{")) ((looking-at "}") (forward-char 1) "}") ((looking-at ",") (forward-char 1) ",") ((looking-at ":") (forward-char 1) - (if (looking-back "case [^:]+:") + (if (looking-back "case [^:]+:" (line-beginning-position 0) t) "case-:" ":")) @@ -297,7 +297,7 @@ "case" "ecase")) ((equal tok "else") - (if (looking-back "\\(guard.*\\)") + (if (looking-back "\\(guard.*\\)" (line-beginning-position) t) "elseguard" "else")) (t tok)))) @@ -312,14 +312,14 @@ ";") ((eq (char-before) ?\{) (backward-char 1) - (if (looking-back "\\(class\\|protocol\\) [^{]+") + (if (looking-back "\\(class\\|protocol\\) [^{]+" (line-beginning-position) t) (concat (match-string 1) "-{") "{")) ((eq (char-before) ?\}) (backward-char 1) "}") ((eq (char-before) ?,) (backward-char 1) ",") ((eq (char-before) ?:) (backward-char 1) - (if (looking-back "case [^:]+") + (if (looking-back "case [^:]+" (line-beginning-position 0)) "case-:" ":")) @@ -354,7 +354,7 @@ "case" "ecase")) ((equal tok "else") - (if (looking-back "\\(guard.*\\)") + (if (looking-back "\\(guard.*\\)" (line-beginning-position) t) "elseguard" "else")) (t tok))))