diff options
| author | Mattias EngdegÄrd | 2019-06-16 13:13:47 +0200 |
|---|---|---|
| committer | Mattias EngdegÄrd | 2019-06-26 11:39:12 +0200 |
| commit | 260b6c2c931d74ef64dacb20b7fcae6f888e6d42 (patch) | |
| tree | 99e952e57c2dfb953b4365fd9ec8c82f5e8ddae8 | |
| parent | 1bc1672f77d15f5f2cda29ce8ce4806bbb6ff71a (diff) | |
| download | emacs-260b6c2c931d74ef64dacb20b7fcae6f888e6d42.tar.gz emacs-260b6c2c931d74ef64dacb20b7fcae6f888e6d42.zip | |
Merge consecutive constant `concat' args (bug#14769)
Suggested by Shigeru Fukaya <shigeru.fukaya@gmail.com>
* lisp/emacs-lisp/byte-opt.el (byte-optimize-concat): New.
(concat): Add byte-optimizer.
| -rw-r--r-- | lisp/emacs-lisp/byte-opt.el | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/lisp/emacs-lisp/byte-opt.el b/lisp/emacs-lisp/byte-opt.el index b0aa407c8b4..2e096016396 100644 --- a/lisp/emacs-lisp/byte-opt.el +++ b/lisp/emacs-lisp/byte-opt.el | |||
| @@ -850,6 +850,33 @@ | |||
| 850 | ',list))))) | 850 | ',list))))) |
| 851 | (byte-optimize-predicate form))) | 851 | (byte-optimize-predicate form))) |
| 852 | 852 | ||
| 853 | (defun byte-optimize-concat (form) | ||
| 854 | "Merge adjacent constant arguments to `concat'." | ||
| 855 | (let ((args (cdr form)) | ||
| 856 | (newargs nil)) | ||
| 857 | (while args | ||
| 858 | (let ((strings nil) | ||
| 859 | val) | ||
| 860 | (while (and args (macroexp-const-p (car args)) | ||
| 861 | (progn | ||
| 862 | (setq val (eval (car args))) | ||
| 863 | (and (or (stringp val) | ||
| 864 | (and (or (listp val) (vectorp val)) | ||
| 865 | (not (memq nil | ||
| 866 | (mapcar #'characterp val)))))))) | ||
| 867 | (push val strings) | ||
| 868 | (setq args (cdr args))) | ||
| 869 | (when strings | ||
| 870 | (let ((s (apply #'concat (nreverse strings)))) | ||
| 871 | (when (not (zerop (length s))) | ||
| 872 | (push s newargs))))) | ||
| 873 | (when args | ||
| 874 | (push (car args) newargs) | ||
| 875 | (setq args (cdr args)))) | ||
| 876 | (if (= (length newargs) (length (cdr form))) | ||
| 877 | form ; No improvement. | ||
| 878 | (cons 'concat (nreverse newargs))))) | ||
| 879 | |||
| 853 | (put 'identity 'byte-optimizer 'byte-optimize-identity) | 880 | (put 'identity 'byte-optimizer 'byte-optimize-identity) |
| 854 | (put 'memq 'byte-optimizer 'byte-optimize-memq) | 881 | (put 'memq 'byte-optimizer 'byte-optimize-memq) |
| 855 | 882 | ||
| @@ -892,6 +919,8 @@ | |||
| 892 | (put 'car-safe 'byte-optimizer 'byte-optimize-predicate) | 919 | (put 'car-safe 'byte-optimizer 'byte-optimize-predicate) |
| 893 | (put 'cdr-safe 'byte-optimizer 'byte-optimize-predicate) | 920 | (put 'cdr-safe 'byte-optimizer 'byte-optimize-predicate) |
| 894 | 921 | ||
| 922 | (put 'concat 'byte-optimizer 'byte-optimize-concat) | ||
| 923 | |||
| 895 | ;; I'm not convinced that this is necessary. Doesn't the optimizer loop | 924 | ;; I'm not convinced that this is necessary. Doesn't the optimizer loop |
| 896 | ;; take care of this? - Jamie | 925 | ;; take care of this? - Jamie |
| 897 | ;; I think this may some times be necessary to reduce ie (quote 5) to 5, | 926 | ;; I think this may some times be necessary to reduce ie (quote 5) to 5, |