From 89bd65197642e4700b36c270d3abf8e4a2dffbf8 Mon Sep 17 00:00:00 2001 From: Mattias EngdegÄrd Date: Mon, 7 Aug 2023 18:14:42 +0200 Subject: Teach byte-compiler about Aristotelian identity * lisp/emacs-lisp/byte-opt.el (byte-optimize-equal, byte-optimize-eq): Optimise (eq X X) -> t where X is a variable; idem for eql and equal. * test/lisp/emacs-lisp/bytecomp-tests.el (bytecomp-tests--test-cases): Add test case. --- test/lisp/emacs-lisp/bytecomp-tests.el | 3 +++ 1 file changed, 3 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 246ffff532f..dd0c1fe91a0 100644 --- a/test/lisp/emacs-lisp/bytecomp-tests.el +++ b/test/lisp/emacs-lisp/bytecomp-tests.el @@ -785,6 +785,9 @@ inner loops respectively." (let ((x 0)) (list (= (setq x 1)) x)) + ;; Aristotelian identity optimisation + (let ((x (bytecomp-test-identity 1))) + (list (eq x x) (eql x x) (equal x x))) ) "List of expressions for cross-testing interpreted and compiled code.") -- cgit v1.2.3