diff options
| author | Richard M. Stallman | 1997-05-06 03:53:10 +0000 |
|---|---|---|
| committer | Richard M. Stallman | 1997-05-06 03:53:10 +0000 |
| commit | 1fa68f218e08d2e1e8ccd54d0061d3012461e46e (patch) | |
| tree | f703b550e701096c125601c25f163193cdadc73d | |
| parent | 3ee4159a4e77c957178791ca394266ab5e1ab235 (diff) | |
| download | emacs-1fa68f218e08d2e1e8ccd54d0061d3012461e46e.tar.gz emacs-1fa68f218e08d2e1e8ccd54d0061d3012461e46e.zip | |
(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.el | 20 |
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 @@ | |||
| 643 | ;; form)) | 643 | ;; form)) |
| 644 | 644 | ||
| 645 | (defun byte-optimize-approx-equal (x y) | 645 | (defun byte-optimize-approx-equal (x y) |
| 646 | (< (* (abs (- x y)) 100) (abs (+ x y)))) | 646 | (<= (* (abs (- x y)) 100) (abs (+ x y)))) |
| 647 | 647 | ||
| 648 | ;; Collect all the constants from FORM, after the STARTth arg, | 648 | ;; Collect all the constants from FORM, after the STARTth arg, |
| 649 | ;; and apply FUN to them to make one argument at the end. | 649 | ;; and apply FUN to them to make one argument at the end. |
| @@ -694,6 +694,20 @@ | |||
| 694 | ;;; (actually, it would be safe if we know the sole arg | 694 | ;;; (actually, it would be safe if we know the sole arg |
| 695 | ;;; is not a marker). | 695 | ;;; is not a marker). |
| 696 | ;; ((null (cdr (cdr form))) (nth 1 form)) | 696 | ;; ((null (cdr (cdr form))) (nth 1 form)) |
| 697 | ((and (null (nthcdr 3 form)) | ||
| 698 | (or (memq (nth 1 form) '(1 -1)) | ||
| 699 | (memq (nth 2 form) '(1 -1)))) | ||
| 700 | ;; Optiize (+ x 1) into (1+ x) and (+ x -1) into (1- x). | ||
| 701 | (let ((integer | ||
| 702 | (if (memq (nth 1 form) '(1 -1)) | ||
| 703 | (nth 1 form) | ||
| 704 | (nth 2 form))) | ||
| 705 | (other | ||
| 706 | (if (memq (nth 1 form) '(1 -1)) | ||
| 707 | (nth 2 form) | ||
| 708 | (nth 1 form)))) | ||
| 709 | (list (if (eq integer 1) '1+ '1-) | ||
| 710 | other))) | ||
| 697 | (t form))) | 711 | (t form))) |
| 698 | 712 | ||
| 699 | (defun byte-optimize-minus (form) | 713 | (defun byte-optimize-minus (form) |
| @@ -705,6 +719,10 @@ | |||
| 705 | ;; (- x y ... 0) --> (- x y ...) | 719 | ;; (- x y ... 0) --> (- x y ...) |
| 706 | (setq form (copy-sequence form)) | 720 | (setq form (copy-sequence form)) |
| 707 | (setcdr (cdr (cdr form)) (delq 0 (nthcdr 3 form)))) | 721 | (setcdr (cdr (cdr form)) (delq 0 (nthcdr 3 form)))) |
| 722 | ((equal (nthcdr 2 form) '(1)) | ||
| 723 | (setq form (list '1- (nth 1 form)))) | ||
| 724 | ((equal (nthcdr 2 form) '(-1)) | ||
| 725 | (setq form (list '1+ (nth 1 form)))) | ||
| 708 | ;; If form is (- CONST foo... CONST), merge first and last. | 726 | ;; If form is (- CONST foo... CONST), merge first and last. |
| 709 | ((and (numberp (nth 1 form)) | 727 | ((and (numberp (nth 1 form)) |
| 710 | (numberp last)) | 728 | (numberp last)) |