Mercurial > hg > xemacs-beta
comparison lisp/byte-optimize.el @ 5651:ae2fdb1fd9e0
Improve for-effect handling in a few places, lisp/
lisp/ChangeLog addition:
2012-05-01 Aidan Kehoe <kehoea@parhasard.net>
* byte-optimize.el (byte-optimize-form-code-walker):
* byte-optimize.el (byte-optimize-or):
Improve handling of for-effect here; we don't need to worry about
discarding multiple values when for-effect is non-nil, this
applies to both #'prog1 and #'or.
* bytecomp.el (progn):
* bytecomp.el (byte-compile-file-form-progn): New.
Put back this function, since it's for-effect there's no need to
worry about passing back multiple values.
* cl-macs.el (cl-pop2):
* cl-macs.el (cl-do-pop):
* cl-macs.el (remf):
* cl.el (pop):
Expand to (prog1 (car-safe PLACE) (setq PLACE (cdr PLACE))) in all
these macros, since that optimizes better (especially for-effect
handling) when byte-compile-delete-errors is nil.
author | Aidan Kehoe <kehoea@parhasard.net> |
---|---|
date | Tue, 01 May 2012 12:43:22 +0100 |
parents | 5b08be74bb53 |
children | cc6f0266bc36 |
comparison
equal
deleted
inserted
replaced
5650:7fa8667cdaa7 | 5651:ae2fdb1fd9e0 |
---|---|
429 (setq tmp (byte-optimize-body (cdr form) for-effect)) | 429 (setq tmp (byte-optimize-body (cdr form) for-effect)) |
430 (if (cdr tmp) (cons 'progn tmp) (car tmp))) | 430 (if (cdr tmp) (cons 'progn tmp) (car tmp))) |
431 (byte-optimize-form (nth 1 form) for-effect))) | 431 (byte-optimize-form (nth 1 form) for-effect))) |
432 ((eq fn 'prog1) | 432 ((eq fn 'prog1) |
433 (if (cdr (cdr form)) | 433 (if (cdr (cdr form)) |
434 (cons 'prog1 | 434 (cons (if for-effect 'progn 'prog1) |
435 (cons (byte-optimize-form (nth 1 form) for-effect) | 435 (cons (byte-optimize-form (nth 1 form) for-effect) |
436 (byte-optimize-body (cdr (cdr form)) t))) | 436 (byte-optimize-body (cdr (cdr form)) t))) |
437 (byte-optimize-form `(or ,(nth 1 form) nil) for-effect))) | 437 (byte-optimize-form `(or ,(nth 1 form) nil) for-effect))) |
438 ((eq fn 'prog2) | 438 ((eq fn 'prog2) |
439 (cons 'prog2 | 439 (cons 'prog2 |
535 | 535 |
536 ((and for-effect | 536 ((and for-effect |
537 (setq tmp (byte-optimize-side-effect-free-p form)) | 537 (setq tmp (byte-optimize-side-effect-free-p form)) |
538 (or byte-compile-delete-errors | 538 (or byte-compile-delete-errors |
539 (eq tmp 'error-free) | 539 (eq tmp 'error-free) |
540 ;; XEmacs; GNU handles the expansion of (pop foo) specially | |
541 ;; here. We changed the macro to expand to (prog1 (car-safe | |
542 ;; PLACE) (setq PLACE (cdr PLACE))) , which has the same | |
543 ;; effect. (This only matters when | |
544 ;; byte-compile-delete-errors is nil, which is usually true | |
545 ;; for GNU and usually false for XEmacs.) | |
540 (progn | 546 (progn |
541 (byte-compile-warn "%s called for effect" | 547 (byte-compile-warn "%s called for effect" |
542 (prin1-to-string form)) | 548 (prin1-to-string form)) |
543 nil))) | 549 nil))) |
544 (byte-compile-log " %s called for effect; deleted" fn) | 550 (byte-compile-log " %s called for effect; deleted" fn) |
945 ((byte-optimize-predicate form)))) | 951 ((byte-optimize-predicate form)))) |
946 | 952 |
947 (defun byte-optimize-or (form) | 953 (defun byte-optimize-or (form) |
948 ;; Throw away unneeded nils, and simplify if less than 2 args. | 954 ;; Throw away unneeded nils, and simplify if less than 2 args. |
949 ;; XEmacs; change to be more careful about discarding multiple values. | 955 ;; XEmacs; change to be more careful about discarding multiple values. |
950 (let* ((memqueued (memq nil form)) | 956 (if (memq nil form) |
951 (trailing-nil (and (cdr memqueued) | 957 (setq form (remove* nil form |
952 (equal '(nil) (last form)))) | 958 ;; A trailing nil indicates to discard multiple |
953 rest) | 959 ;; values, and we need to respect that. No need if |
954 ;; A trailing nil indicates to discard multiple values, and we need to | 960 ;; this is for-effect, though, multiple values |
955 ;; respect that: | 961 ;; will be discarded anyway. |
956 (when (and memqueued (cdr memqueued)) | 962 :end (if (not for-effect) (1- (length form)))))) |
957 (setq form (delq nil (copy-sequence form))) | 963 ;; If there is a literal non-nil constant in the args to `or', throw |
958 (when trailing-nil | 964 ;; away all following forms. We can do this because a literal non-nil |
959 (setcdr (last form) '(nil)))) | 965 ;; constant cannot be multiple. |
960 (setq rest form) | 966 (let ((rest form)) |
961 ;; If there is a literal non-nil constant in the args to `or', throw | |
962 ;; away all following forms. We can do this because a literal non-nil | |
963 ;; constant cannot be multiple. | |
964 (while (cdr (setq rest (cdr rest))) | 967 (while (cdr (setq rest (cdr rest))) |
965 (if (byte-compile-trueconstp (car rest)) | 968 (if (byte-compile-trueconstp (car rest)) |
966 (setq form (copy-sequence form) | 969 (setq form (copy-sequence form) |
967 rest (setcdr (memq (car rest) form) nil)))) | 970 rest (setcdr (memq (car rest) form) nil)))) |
968 (if (cdr (cdr form)) | 971 (if (cdr (cdr form)) |