diff options
| author | Mattias EngdegÄrd | 2020-07-06 17:38:52 +0200 |
|---|---|---|
| committer | Mattias EngdegÄrd | 2020-07-06 18:08:06 +0200 |
| commit | 3f990c3cccf85e64399bf98ea3e61cb618e8455c (patch) | |
| tree | 54bd70ca572b47a4cb36931cd6306e25d4edf1b9 | |
| parent | fb63a64d2159be9cd9bf63a0a6ebff582e385528 (diff) | |
| download | emacs-3f990c3cccf85e64399bf98ea3e61cb618e8455c.tar.gz emacs-3f990c3cccf85e64399bf98ea3e61cb618e8455c.zip | |
Simplify byte-code optimisation of pure functions
Most pure functions need no explicit optimisation; we can do away with
almost all uses of byte-optimize-predicate (now renamed to
byte-optimize-constant-args, since it is not just for predicates).
Also remove some superfluous arity warnings.
* lisp/emacs-lisp/byte-opt.el (byte-optimize-identity, byte-optimize-memq)
(byte-optimize-nth, byte-optimize-nthcdr):
Remove arity warnings and simplify.
* lisp/emacs-lisp/byte-opt.el (<, >, <=, >=, not, null, consp, listp)
(symbolp, stringp, string<, string-lessp, proper-list-p, logand)
(logior, logxor, lognot, car, cdr, car-safe, cdr-safe):
Remove superfluous byte-optimizer property.
(byte-optimize-predicate): Rename to byte-optimize-constant-args.
All uses changed.
| -rw-r--r-- | lisp/emacs-lisp/byte-opt.el | 57 |
1 files changed, 14 insertions, 43 deletions
diff --git a/lisp/emacs-lisp/byte-opt.el b/lisp/emacs-lisp/byte-opt.el index 971e4ddbcc9..646994a37c1 100644 --- a/lisp/emacs-lisp/byte-opt.el +++ b/lisp/emacs-lisp/byte-opt.el | |||
| @@ -795,7 +795,7 @@ | |||
| 795 | (t ;; This can enable some lapcode optimizations. | 795 | (t ;; This can enable some lapcode optimizations. |
| 796 | (list (car form) (nth 2 form) (nth 1 form))))) | 796 | (list (car form) (nth 2 form) (nth 1 form))))) |
| 797 | 797 | ||
| 798 | (defun byte-optimize-predicate (form) | 798 | (defun byte-optimize-constant-args (form) |
| 799 | (let ((ok t) | 799 | (let ((ok t) |
| 800 | (rest (cdr form))) | 800 | (rest (cdr form))) |
| 801 | (while (and rest ok) | 801 | (while (and rest ok) |
| @@ -810,9 +810,6 @@ | |||
| 810 | (defun byte-optimize-identity (form) | 810 | (defun byte-optimize-identity (form) |
| 811 | (if (and (cdr form) (null (cdr (cdr form)))) | 811 | (if (and (cdr form) (null (cdr (cdr form)))) |
| 812 | (nth 1 form) | 812 | (nth 1 form) |
| 813 | (byte-compile-warn "identity called with %d arg%s, but requires 1" | ||
| 814 | (length (cdr form)) | ||
| 815 | (if (= 1 (length (cdr form))) "" "s")) | ||
| 816 | form)) | 813 | form)) |
| 817 | 814 | ||
| 818 | (defun byte-optimize--constant-symbol-p (expr) | 815 | (defun byte-optimize--constant-symbol-p (expr) |
| @@ -847,19 +844,16 @@ | |||
| 847 | 844 | ||
| 848 | (defun byte-optimize-memq (form) | 845 | (defun byte-optimize-memq (form) |
| 849 | ;; (memq foo '(bar)) => (and (eq foo 'bar) '(bar)) | 846 | ;; (memq foo '(bar)) => (and (eq foo 'bar) '(bar)) |
| 850 | (if (/= (length (cdr form)) 2) | 847 | (if (= (length (cdr form)) 2) |
| 851 | (byte-compile-warn "memq called with %d arg%s, but requires 2" | 848 | (let ((list (nth 2 form))) |
| 852 | (length (cdr form)) | 849 | (if (and (eq (car-safe list) 'quote) |
| 853 | (if (= 1 (length (cdr form))) "" "s")) | ||
| 854 | (let ((list (nth 2 form))) | ||
| 855 | (when (and (eq (car-safe list) 'quote) | ||
| 856 | (listp (setq list (cadr list))) | 850 | (listp (setq list (cadr list))) |
| 857 | (= (length list) 1)) | 851 | (= (length list) 1)) |
| 858 | (setq form (byte-optimize-and | 852 | `(and (eq ,(nth 1 form) ',(nth 0 list)) |
| 859 | `(and ,(byte-optimize-predicate | 853 | ',list) |
| 860 | `(eq ,(nth 1 form) ',(nth 0 list))) | 854 | form)) |
| 861 | ',list))))) | 855 | ;; Arity errors reported elsewhere. |
| 862 | (byte-optimize-predicate form))) | 856 | form)) |
| 863 | 857 | ||
| 864 | (defun byte-optimize-concat (form) | 858 | (defun byte-optimize-concat (form) |
| 865 | "Merge adjacent constant arguments to `concat'." | 859 | "Merge adjacent constant arguments to `concat'." |
| @@ -907,31 +901,8 @@ | |||
| 907 | (put 'string= 'byte-optimizer 'byte-optimize-binary-predicate) | 901 | (put 'string= 'byte-optimizer 'byte-optimize-binary-predicate) |
| 908 | (put 'string-equal 'byte-optimizer 'byte-optimize-binary-predicate) | 902 | (put 'string-equal 'byte-optimizer 'byte-optimize-binary-predicate) |
| 909 | 903 | ||
| 910 | (put '< 'byte-optimizer 'byte-optimize-predicate) | ||
| 911 | (put '> 'byte-optimizer 'byte-optimize-predicate) | ||
| 912 | (put '<= 'byte-optimizer 'byte-optimize-predicate) | ||
| 913 | (put '>= 'byte-optimizer 'byte-optimize-predicate) | ||
| 914 | (put '1+ 'byte-optimizer 'byte-optimize-1+) | 904 | (put '1+ 'byte-optimizer 'byte-optimize-1+) |
| 915 | (put '1- 'byte-optimizer 'byte-optimize-1-) | 905 | (put '1- 'byte-optimizer 'byte-optimize-1-) |
| 916 | (put 'not 'byte-optimizer 'byte-optimize-predicate) | ||
| 917 | (put 'null 'byte-optimizer 'byte-optimize-predicate) | ||
| 918 | (put 'consp 'byte-optimizer 'byte-optimize-predicate) | ||
| 919 | (put 'listp 'byte-optimizer 'byte-optimize-predicate) | ||
| 920 | (put 'symbolp 'byte-optimizer 'byte-optimize-predicate) | ||
| 921 | (put 'stringp 'byte-optimizer 'byte-optimize-predicate) | ||
| 922 | (put 'string< 'byte-optimizer 'byte-optimize-predicate) | ||
| 923 | (put 'string-lessp 'byte-optimizer 'byte-optimize-predicate) | ||
| 924 | (put 'proper-list-p 'byte-optimizer 'byte-optimize-predicate) | ||
| 925 | |||
| 926 | (put 'logand 'byte-optimizer 'byte-optimize-predicate) | ||
| 927 | (put 'logior 'byte-optimizer 'byte-optimize-predicate) | ||
| 928 | (put 'logxor 'byte-optimizer 'byte-optimize-predicate) | ||
| 929 | (put 'lognot 'byte-optimizer 'byte-optimize-predicate) | ||
| 930 | |||
| 931 | (put 'car 'byte-optimizer 'byte-optimize-predicate) | ||
| 932 | (put 'cdr 'byte-optimizer 'byte-optimize-predicate) | ||
| 933 | (put 'car-safe 'byte-optimizer 'byte-optimize-predicate) | ||
| 934 | (put 'cdr-safe 'byte-optimizer 'byte-optimize-predicate) | ||
| 935 | 906 | ||
| 936 | (put 'concat 'byte-optimizer 'byte-optimize-concat) | 907 | (put 'concat 'byte-optimizer 'byte-optimize-concat) |
| 937 | 908 | ||
| @@ -962,7 +933,7 @@ | |||
| 962 | nil)) | 933 | nil)) |
| 963 | ((null (cdr (cdr form))) | 934 | ((null (cdr (cdr form))) |
| 964 | (nth 1 form)) | 935 | (nth 1 form)) |
| 965 | ((byte-optimize-predicate form)))) | 936 | ((byte-optimize-constant-args form)))) |
| 966 | 937 | ||
| 967 | (defun byte-optimize-or (form) | 938 | (defun byte-optimize-or (form) |
| 968 | ;; Throw away nil's, and simplify if less than 2 args. | 939 | ;; Throw away nil's, and simplify if less than 2 args. |
| @@ -975,7 +946,7 @@ | |||
| 975 | (setq form (copy-sequence form) | 946 | (setq form (copy-sequence form) |
| 976 | rest (setcdr (memq (car rest) form) nil)))) | 947 | rest (setcdr (memq (car rest) form) nil)))) |
| 977 | (if (cdr (cdr form)) | 948 | (if (cdr (cdr form)) |
| 978 | (byte-optimize-predicate form) | 949 | (byte-optimize-constant-args form) |
| 979 | (nth 1 form)))) | 950 | (nth 1 form)))) |
| 980 | 951 | ||
| 981 | (defun byte-optimize-cond (form) | 952 | (defun byte-optimize-cond (form) |
| @@ -1122,7 +1093,7 @@ | |||
| 1122 | (list 'car (if (zerop (nth 1 form)) | 1093 | (list 'car (if (zerop (nth 1 form)) |
| 1123 | (nth 2 form) | 1094 | (nth 2 form) |
| 1124 | (list 'cdr (nth 2 form)))) | 1095 | (list 'cdr (nth 2 form)))) |
| 1125 | (byte-optimize-predicate form)) | 1096 | form) |
| 1126 | form)) | 1097 | form)) |
| 1127 | 1098 | ||
| 1128 | (put 'nthcdr 'byte-optimizer 'byte-optimize-nthcdr) | 1099 | (put 'nthcdr 'byte-optimizer 'byte-optimize-nthcdr) |
| @@ -1134,7 +1105,7 @@ | |||
| 1134 | (while (>= (setq count (1- count)) 0) | 1105 | (while (>= (setq count (1- count)) 0) |
| 1135 | (setq form (list 'cdr form))) | 1106 | (setq form (list 'cdr form))) |
| 1136 | form) | 1107 | form) |
| 1137 | (byte-optimize-predicate form)) | 1108 | form) |
| 1138 | form)) | 1109 | form)) |
| 1139 | 1110 | ||
| 1140 | ;; Fixme: delete-char -> delete-region (byte-coded) | 1111 | ;; Fixme: delete-char -> delete-region (byte-coded) |
| @@ -2208,7 +2179,7 @@ If FOR-EFFECT is non-nil, the return value is assumed to be of no importance." | |||
| 2208 | (or noninteractive (message "compiling %s...done" x))) | 2179 | (or noninteractive (message "compiling %s...done" x))) |
| 2209 | '(byte-optimize-form | 2180 | '(byte-optimize-form |
| 2210 | byte-optimize-body | 2181 | byte-optimize-body |
| 2211 | byte-optimize-predicate | 2182 | byte-optimize-constant-args |
| 2212 | byte-optimize-binary-predicate | 2183 | byte-optimize-binary-predicate |
| 2213 | ;; Inserted some more than necessary, to speed it up. | 2184 | ;; Inserted some more than necessary, to speed it up. |
| 2214 | byte-optimize-form-code-walker | 2185 | byte-optimize-form-code-walker |