From 75f04848a653e70f12f0e5a62b756c5bba0dd204 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mattias=20Engdeg=C3=A5rd?= Date: Sun, 12 Mar 2023 17:00:25 +0100 Subject: Repair and speed up safe-copy-tree and make it internal (bug#61962) There is no particular requirement for safe-copy-tree so let's make it internal for now. The new implementation is faster and more correct. * doc/lispref/lists.texi (Building Lists): * etc/NEWS: Remove doc and announcement. * lisp/subr.el (safe-copy-tree--seen, safe-copy-tree--1) (safe-copy-tree): Remove old version. * lisp/emacs-lisp/bytecomp.el (bytecomp--copy-tree-seen) (bytecomp--copy-tree-1, bytecomp--copy-tree): Add new version. (byte-compile-initial-macro-environment): Use it. * test/lisp/subr-tests.el (subr--safe-copy-tree): * test/lisp/emacs-lisp/bytecomp-tests.el (bytecomp--copy-tree): Move and improve tests. --- test/lisp/emacs-lisp/bytecomp-tests.el | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) (limited to 'test/lisp/emacs-lisp') diff --git a/test/lisp/emacs-lisp/bytecomp-tests.el b/test/lisp/emacs-lisp/bytecomp-tests.el index 10b009a261c..2cd4dd75742 100644 --- a/test/lisp/emacs-lisp/bytecomp-tests.el +++ b/test/lisp/emacs-lisp/bytecomp-tests.el @@ -1850,6 +1850,34 @@ EXPECTED-POINT BINDINGS (MODES \\='\\='(ruby-mode js-mode python-mode)) \ (should (eq (byte-compile-file src-file) 'no-byte-compile)) (should-not (file-exists-p dest-file)))) +(ert-deftest bytecomp--copy-tree () + (should (null (bytecomp--copy-tree nil))) + (let ((print-circle t)) + (let* ((x '(1 2 (3 4))) + (y (bytecomp--copy-tree x))) + (should (equal (prin1-to-string (list x y)) + "((1 2 (3 4)) (1 2 (3 4)))"))) + (let* ((x '#1=(a #1#)) + (y (bytecomp--copy-tree x))) + (should (equal (prin1-to-string (list x y)) + "(#1=(a #1#) #2=(a #2#))"))) + (let* ((x '#1=(#1# a)) + (y (bytecomp--copy-tree x))) + (should (equal (prin1-to-string (list x y)) + "(#1=(#1# a) #2=(#2# a))"))) + (let* ((x '((a . #1=(b)) #1#)) + (y (bytecomp--copy-tree x))) + (should (equal (prin1-to-string (list x y)) + "(((a . #1=(b)) #1#) ((a . #2=(b)) #2#))"))) + (let* ((x '#1=(a #2=(#1# b . #3=(#2# c . #1#)) (#3# d))) + (y (bytecomp--copy-tree x))) + (should (equal (prin1-to-string (list x y)) + (concat + "(" + "#1=(a #2=(#1# b . #3=(#2# c . #1#)) (#3# d))" + " " + "#4=(a #5=(#4# b . #6=(#5# c . #4#)) (#6# d))" + ")")))))) ;; Local Variables: ;; no-byte-compile: t -- cgit v1.2.1