emacs-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

master 35b4205dee: Improve save-match-data hygiene


From: Mattias Engdegård
Subject: master 35b4205dee: Improve save-match-data hygiene
Date: Wed, 7 Sep 2022 12:03:09 -0400 (EDT)

branch: master
commit 35b4205dee6c65e3e0fd00708eb95c84f2ca49e6
Author: Mattias Engdegård <mattiase@acm.org>
Commit: Mattias Engdegård <mattiase@acm.org>

    Improve save-match-data hygiene
    
    * lisp/subr.el (save-match-data): Use uninterned variable symbol.
    Remove outdated comments.
---
 lisp/subr.el | 17 ++++++-----------
 1 file changed, 6 insertions(+), 11 deletions(-)

diff --git a/lisp/subr.el b/lisp/subr.el
index 03d678f20d..c7b86c83e8 100644
--- a/lisp/subr.el
+++ b/lisp/subr.el
@@ -4956,10 +4956,6 @@ If `default-directory' is already an existing directory, 
it's not changed."
 
 ;;; Matching and match data.
 
-;; We use save-match-data-internal as the local variable because
-;; that works ok in practice (people should not use that variable elsewhere).
-;; We used to use an uninterned symbol; the compiler handles that properly
-;; now, but it generates slower code.
 (defmacro save-match-data (&rest body)
   "Execute the BODY forms, restoring the global value of the match data.
 The value returned is the value of the last form in BODY.
@@ -4971,13 +4967,12 @@ rather than your caller's match data."
   ;; because that makes a bootstrapping problem
   ;; if you need to recompile all the Lisp files using interpreted code.
   (declare (indent 0) (debug t))
-  (list 'let
-       '((save-match-data-internal (match-data)))
-       (list 'unwind-protect
-             (cons 'progn body)
-             ;; It is safe to free (evaporate) markers immediately here,
-             ;; as Lisp programs should not copy from save-match-data-internal.
-             '(set-match-data save-match-data-internal 'evaporate))))
+  (let ((saved-match-data (make-symbol "saved-match-data")))
+    (list 'let
+         (list (list saved-match-data '(match-data)))
+         (list 'unwind-protect
+               (cons 'progn body)
+               (list 'set-match-data saved-match-data t)))))
 
 (defun match-string (num &optional string)
   "Return the string of text matched by the previous search or regexp 
operation.



reply via email to

[Prev in Thread] Current Thread [Next in Thread]