summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRichard M. Stallman <rms@gnu.org>1997-05-06 03:53:10 +0000
committerRichard M. Stallman <rms@gnu.org>1997-05-06 03:53:10 +0000
commitc2ef5fb966ce0bbc2f397072eaa899ed8cdfc9c1 (patch)
tree314d2204d9302137b9b684209f6fab84b92bd454
parent1b252a7f8be7f2de9dd41c723830a28a64aa6df9 (diff)
downloademacs-c2ef5fb966ce0bbc2f397072eaa899ed8cdfc9c1.tar.gz
(byte-optimize-approx-equal): Use <=, not <.
(byte-optimize-minus, byte-optimize-plus): Optimize adding or subtracting 1.
-rw-r--r--lisp/emacs-lisp/byte-opt.el20
1 files changed, 19 insertions, 1 deletions
diff --git a/lisp/emacs-lisp/byte-opt.el b/lisp/emacs-lisp/byte-opt.el
index 4b7b9f305e6..c75dbe4b696 100644
--- a/lisp/emacs-lisp/byte-opt.el
+++ b/lisp/emacs-lisp/byte-opt.el
@@ -643,7 +643,7 @@
;; form))
(defun byte-optimize-approx-equal (x y)
- (< (* (abs (- x y)) 100) (abs (+ x y))))
+ (<= (* (abs (- x y)) 100) (abs (+ x y))))
;; Collect all the constants from FORM, after the STARTth arg,
;; and apply FUN to them to make one argument at the end.
@@ -694,6 +694,20 @@
;;; (actually, it would be safe if we know the sole arg
;;; is not a marker).
;; ((null (cdr (cdr form))) (nth 1 form))
+ ((and (null (nthcdr 3 form))
+ (or (memq (nth 1 form) '(1 -1))
+ (memq (nth 2 form) '(1 -1))))
+ ;; Optiize (+ x 1) into (1+ x) and (+ x -1) into (1- x).
+ (let ((integer
+ (if (memq (nth 1 form) '(1 -1))
+ (nth 1 form)
+ (nth 2 form)))
+ (other
+ (if (memq (nth 1 form) '(1 -1))
+ (nth 2 form)
+ (nth 1 form))))
+ (list (if (eq integer 1) '1+ '1-)
+ other)))
(t form)))
(defun byte-optimize-minus (form)
@@ -705,6 +719,10 @@
;; (- x y ... 0) --> (- x y ...)
(setq form (copy-sequence form))
(setcdr (cdr (cdr form)) (delq 0 (nthcdr 3 form))))
+ ((equal (nthcdr 2 form) '(1))
+ (setq form (list '1- (nth 1 form))))
+ ((equal (nthcdr 2 form) '(-1))
+ (setq form (list '1+ (nth 1 form))))
;; If form is (- CONST foo... CONST), merge first and last.
((and (numberp (nth 1 form))
(numberp last))