branch: externals/relint commit 62ca3d4dc94986de1cb948fc28582ea22a415ad0 Author: Mattias Engdegård <matti...@acm.org> Commit: Mattias Engdegård <matti...@acm.org>
Slight performance improvement Remove a function call in the inner loop in the common case. --- trawl.el | 158 ++++++++++++++++++++++++++++++--------------------------------- 1 file changed, 74 insertions(+), 84 deletions(-) diff --git a/trawl.el b/trawl.el index ab4295b..48ef364 100644 --- a/trawl.el +++ b/trawl.el @@ -245,92 +245,82 @@ (trawl--peel-list form))) (defun trawl--check-form-recursively (form file pos path) - (when (consp form) - (pcase form -; (`(apply ,(or `nconc `(quote nconc) `(function nconc)) (mapcar . ,_)) -; (trawl--report file pos path -; "use mapcan instead of (apply nconc (mapcar...))")) -; (`(lambda (,var1) (,_ ,var2)) -; (when (eq var1 var2) -; (trawl--report file pos path -; "lambda expression can be η-reduced"))) -; (`(lambda (,var1) ,var2) -; (when (eq var1 var2) -; (trawl--report file pos path -; "lambda expression is #'identity"))) -; (`(defun ,name ,_ . ,body) -; (let ((f body)) -; (while (and f (consp (car f)) (eq (caar f) 'declare)) -; (setq f (cdr f))) -; (when (and f (consp (car f))) -; (setq f (cdr f)) -; (while (cdr f) -; (when (stringp (car f)) -; (trawl--report file pos path -; (format "defun %s: misplaced doc string" name))) -; (setq f (cdr f)))))) - (`(,(or `looking-at `re-search-forward `re-search-backward - `string-match `string-match-p `looking-back `looking-at-p - `replace-regexp-in-string 'replace-regexp - `query-replace-regexp - `posix-looking-at `posix-search-backward `posix-search-forward - `posix-string-match) - ,re-arg . ,_) - (unless (and (symbolp re-arg) - (memq re-arg trawl--checked-variables)) - (trawl--check-re re-arg (format "call to %s" (car form)) - file pos (cons 1 path)))) - (`(,(or `defvar `defconst 'defcustom) - ,name ,re-arg . ,rest) - (when (symbolp name) - (cond - ((string-match-p (rx (or "-regexp" "-re" "-regex" "-pattern") eos) - (symbol-name name)) - (trawl--check-re re-arg name file pos (cons 2 path)) - (push name trawl--checked-variables)) - ((string-match-p (rx (or "-regexps" "-regexes" "-patterns") eos) - (symbol-name name)) - (trawl--check-list re-arg name file pos (cons 2 path)) - (push name trawl--checked-variables)) - ((string-match-p (rx "-font-lock-keywords" eos) - (symbol-name name)) - (trawl--check-font-lock-keywords re-arg name file pos (cons 2 path)) - (push name trawl--checked-variables)) - ((eq name 'compilation-error-regexp-alist-alist) - (trawl--check-compilation-error-regexp-alist-alist - re-arg name file pos (cons 2 path)) - (push name trawl--checked-variables)) - ((string-match-p (rx (or "-regexp" "-re" "-regex" "-pattern") - "-alist" eos) - (symbol-name name)) - (trawl--check-list-car re-arg name file pos (cons 2 path)) - (push name trawl--checked-variables)) - ((string-match-p (rx "-rules-list" eos) - (symbol-name name)) - (trawl--check-rules-list re-arg name file pos (cons 2 path)) - (push name trawl--checked-variables)) - ;; Doc string starting with "regexp"? - ((and (stringp (car rest)) - (let ((case-fold-search t)) - (string-match-p (rx bos "regexp") (car rest)))) - (trawl--check-re re-arg name file pos (cons 2 path)) - (push name trawl--checked-variables)) - ) - (push (cons name re-arg) trawl--variables))) - (`(define-generic-mode ,name ,_ ,_ ,font-lock-list ,auto-mode-list . ,_) - (let ((origin (format "define-generic-mode %s" name))) - (trawl--check-font-lock-keywords font-lock-list origin - file pos (cons 4 path)) - (trawl--check-list auto-mode-list origin file pos (cons 5 path)))) - ) - (let ((index 0)) - (while (consp form) - (trawl--check-form-recursively (car form) file pos (cons index path)) - (setq form (cdr form)) - (setq index (1+ index)))))) + (pcase form +;;; (`(defun ,name ,_ . ,body) +;;; (let ((f body)) +;;; (while (and f (consp (car f)) (eq (caar f) 'declare)) +;;; (setq f (cdr f))) +;;; (when (and f (consp (car f))) +;;; (setq f (cdr f)) +;;; (while (cdr f) +;;; (when (stringp (car f)) +;;; (trawl--report file pos path +;;; (format "defun %s: misplaced doc string" name))) +;;; (setq f (cdr f)))))) + (`(,(or `looking-at `re-search-forward `re-search-backward + `string-match `string-match-p `looking-back `looking-at-p + `replace-regexp-in-string `replace-regexp + `query-replace-regexp + `posix-looking-at `posix-search-backward `posix-search-forward + `posix-string-match) + ,re-arg . ,_) + (unless (and (symbolp re-arg) + (memq re-arg trawl--checked-variables)) + (trawl--check-re re-arg (format "call to %s" (car form)) + file pos (cons 1 path)))) + (`(,(or `defvar `defconst `defcustom) + ,name ,re-arg . ,rest) + (when (symbolp name) + (cond + ((string-match-p (rx (or "-regexp" "-re" "-regex" "-pattern") eos) + (symbol-name name)) + (trawl--check-re re-arg name file pos (cons 2 path)) + (push name trawl--checked-variables)) + ((string-match-p (rx (or "-regexps" "-regexes" "-patterns") eos) + (symbol-name name)) + (trawl--check-list re-arg name file pos (cons 2 path)) + (push name trawl--checked-variables)) + ((string-match-p (rx "-font-lock-keywords" eos) + (symbol-name name)) + (trawl--check-font-lock-keywords re-arg name file pos (cons 2 path)) + (push name trawl--checked-variables)) + ((eq name 'compilation-error-regexp-alist-alist) + (trawl--check-compilation-error-regexp-alist-alist + re-arg name file pos (cons 2 path)) + (push name trawl--checked-variables)) + ((string-match-p (rx (or "-regexp" "-re" "-regex" "-pattern") + "-alist" eos) + (symbol-name name)) + (trawl--check-list-car re-arg name file pos (cons 2 path)) + (push name trawl--checked-variables)) + ((string-match-p (rx "-rules-list" eos) + (symbol-name name)) + (trawl--check-rules-list re-arg name file pos (cons 2 path)) + (push name trawl--checked-variables)) + ;; Doc string starting with "regexp"? + ((and (stringp (car rest)) + (let ((case-fold-search t)) + (string-match-p (rx bos "regexp") (car rest)))) + (trawl--check-re re-arg name file pos (cons 2 path)) + (push name trawl--checked-variables)) + ) + (push (cons name re-arg) trawl--variables))) + (`(define-generic-mode ,name ,_ ,_ ,font-lock-list ,auto-mode-list . ,_) + (let ((origin (format "define-generic-mode %s" name))) + (trawl--check-font-lock-keywords font-lock-list origin + file pos (cons 4 path)) + (trawl--check-list auto-mode-list origin file pos (cons 5 path)))) + ) + (let ((index 0)) + (while (consp form) + (when (consp (car form)) + (trawl--check-form-recursively (car form) file pos (cons index path))) + (setq form (cdr form)) + (setq index (1+ index))))) (defun trawl--check-toplevel-form (form file pos) - (trawl--check-form-recursively form file pos nil)) + (when (consp form) + (trawl--check-form-recursively form file pos nil))) (defun trawl--show-errors () (unless noninteractive