From: Eshel Yaron Date: Sat, 10 Aug 2024 15:02:33 +0000 (+0200) Subject: scope.el: Prefer 'nconc' where possible X-Git-Url: http://git.eshelyaron.com/gitweb/?a=commitdiff_plain;h=27d1a83d687c695ea7dd6e8954ba518a89f588aa;p=emacs.git scope.el: Prefer 'nconc' where possible --- diff --git a/lisp/emacs-lisp/scope.el b/lisp/emacs-lisp/scope.el index e006948d3cd..423effea49b 100644 --- a/lisp/emacs-lisp/scope.el +++ b/lisp/emacs-lisp/scope.el @@ -36,7 +36,7 @@ (list (list beg len (alist-get bare local)))))) (defun scope-let (local bindings body) - (append + (nconc (mapcan (lambda (binding) (if (consp binding) (cons @@ -64,7 +64,7 @@ (defun scope-let* (local bindings body) (if bindings (let ((binding (car bindings))) - (append + (nconc (if (consp binding) (cons (let* ((sym (car binding)) @@ -134,7 +134,7 @@ (eq (bare-symbol (caar body)) 'interactive)) (setq int-spec (cadar body)) (setq body (cdr body))) - (append + (nconc (seq-keep (lambda (arg) (and (symbol-with-pos-p arg) (not (memq (bare-symbol arg) '(&optional &rest _))) @@ -168,7 +168,7 @@ (len (length (symbol-name bare)))) (cons (list beg len beg) - (append + (nconc (cond ((consp spec) (let ((head (car spec)) @@ -188,7 +188,7 @@ (len (length (symbol-name bare)))) (cons (list beg len beg) - (append + (nconc (cond ((consp spec) (let ((head (car spec)) @@ -207,7 +207,7 @@ (len (length (symbol-name bare)))) (cons (list beg len beg) - (append + (nconc (scope-1 local0 init) (when svar (let ((sbeg (symbol-with-pos-pos svar))) @@ -229,7 +229,7 @@ (expr (car expr-type)) (type (cadr expr-type)) (more (cddr args))) - (append + (nconc (scope-1 local0 expr) (cond ((consp type) @@ -268,7 +268,7 @@ (scope-defgeneric-1 local name args (cdr body))) ((and (consp (car body)) (symbol-with-pos-p (caar body)) (eq (bare-symbol (caar body)) :method)) - (append + (nconc (scope-defmethod local nil (cdar body)) (scope-defgeneric-1 local name args (cdr body)))) ;; FIXME: `args' may include `&key', so defun is not a perfect match. @@ -282,7 +282,7 @@ (scope-defgeneric-1 local name args (cdr body))) ((and (consp (car body)) (symbol-with-pos-p (caar body)) (eq (bare-symbol (caar body)) :method)) - (append + (nconc (scope-defmethod local nil (cdar body)) (scope-defgeneric-1 local name args (cdr body)))) (t (scope-defgeneric-2 local name args body)))) @@ -301,7 +301,7 @@ (defun scope-defvar (local _sym init) (scope-1 local init)) (defun scope-condition-case (local var bodyform handlers) - (append + (nconc (when var (let* ((beg (symbol-with-pos-pos var)) (bare (bare-symbol var))) @@ -317,7 +317,7 @@ (let* ((beg (symbol-with-pos-pos var)) (bare (bare-symbol var))) (list beg (length (symbol-name bare)) beg)) - (append + (nconc (scope-1 local lst) (scope-1 local res) (let ((l (cons (cons (bare-symbol var) (symbol-with-pos-pos var)) local))) @@ -331,7 +331,7 @@ (l (car l-r0)) (r0 (cdr l-r0)) (l-r (scope-pcase-qpat l (cdr qpat)))) - (cons (car l-r) (append r0 (cdr l-r)))))) + (cons (car l-r) (nconc r0 (cdr l-r)))))) ;; FIXME: Support vector qpats. (t (list local)))) @@ -354,10 +354,10 @@ (let* ((l-r (scope-pcase-pattern local pattern)) (l (car l-r)) (r (cdr l-r))) - (when l (append r (scope-n l body))))) + (when l (nconc r (scope-n l body))))) (defun scope-pcase (local exp cases) - (append + (nconc (scope-1 local exp) (mapcan (lambda (case) @@ -365,10 +365,10 @@ cases))) (defun scope-push (local new place) - (append (scope-1 local new) (scope-1 local place))) + (nconc (scope-1 local new) (scope-1 local place))) (defun scope-minibuffer-with-setup-hook (local fun body) - (append + (nconc (scope-1 local (if (and (symbol-with-pos-p (car-safe fun)) (eq :append (bare-symbol (car-safe fun)))) (cadr fun) @@ -394,7 +394,7 @@ (cons (list (symbol-with-pos-pos func) (length (symbol-name (bare-symbol func))) (symbol-with-pos-pos func)) - (append + (nconc (if (cdr exps) ;; def is (FUNC ARGLIST BODY...) (scope-defun local nil (car exps) (cdr exps)) @@ -418,7 +418,7 @@ (symbol-with-pos-pos func)) (let ((scope-flet-list (cons (bare-symbol func) scope-flet-list)) (l (cons (cons (bare-symbol func) (symbol-with-pos-pos func)) local))) - (append + (nconc (scope-defun l nil args body) (scope-flet l (cdr defs) forms))))) (scope-n local forms))) @@ -448,7 +448,7 @@ (len (length (symbol-name bare)))) (cons (list beg len beg) - (append + (nconc (scope-1 local init) (scope-cl-defun-aux (cons (cons bare beg) local) name (cdr args) body))))))) @@ -483,7 +483,7 @@ (len (length (symbol-name bare)))) (cons (list beg len beg) - (append + (nconc (scope-1 local init) (when svar (let ((sbeg (symbol-with-pos-pos svar))) @@ -544,7 +544,7 @@ (len (length (symbol-name bare)))) (cons (list beg len beg) - (append + (nconc (scope-1 local init) (when svar (let ((sbeg (symbol-with-pos-pos svar))) @@ -588,26 +588,25 @@ (defun scope-seq-let (local args sequence body) (nconc (scope-1 local sequence) - (append - (mapcar (lambda (arg) - (let* ((beg (symbol-with-pos-pos arg)) - (bare (bare-symbol arg)) - (len (length (symbol-name bare)))) - (list beg len beg))) - args) - (scope-n (append - (mapcar (lambda (arg) - (cons (bare-symbol arg) (symbol-with-pos-pos arg))) - args) - local) - body)))) + (mapcar (lambda (arg) + (let* ((beg (symbol-with-pos-pos arg)) + (bare (bare-symbol arg)) + (len (length (symbol-name bare)))) + (list beg len beg))) + args) + (scope-n (append + (mapcar (lambda (arg) + (cons (bare-symbol arg) (symbol-with-pos-pos arg))) + args) + local) + body))) (defun scope-pcase-lambda (local lambda-list body) (if lambda-list (let* ((l-r (scope-pcase-pattern local (car lambda-list))) (l (car l-r)) (r (cdr l-r))) - (when l (append r (scope-pcase-lambda l (cdr lambda-list) body)))) + (when l (nconc r (scope-pcase-lambda l (cdr lambda-list) body)))) (scope-n local body))) (defun scope-pcase-dolist (local pattern lst body) @@ -763,8 +762,8 @@ (lambda (forms) (scope-condition-case local (car forms) (cadr forms) (cddr forms)))) (t #'ignore))) ((memq bare scope-flet-list) - (lambda (forms) (append (scope-s local f) - (scope-n local forms)))) + (lambda (forms) (nconc (scope-s local f) + (scope-n local forms)))) ;; FIXME: Assume unknown symbols refer to functions, unless at ;; top level. (t #'ignore))))