diff options
| author | Mario Lang | 2016-07-10 01:18:47 +0200 |
|---|---|---|
| committer | Mario Lang | 2016-07-10 01:18:47 +0200 |
| commit | 466ee1b3ea76425d201b5d59950e88251870c836 (patch) | |
| tree | e9fffa1695adbabcaba923e3dfe0bb928f57008a /src | |
| parent | c3223dd505ba0ecde57371eae7e9a59637a852e4 (diff) | |
| download | emacs-466ee1b3ea76425d201b5d59950e88251870c836.tar.gz emacs-466ee1b3ea76425d201b5d59950e88251870c836.zip | |
An efficient built-in mapcan
A built-in version of `mapcan' avoids consing up (and GC'ing) the
intermediate list.
* src/fns.c (Fmapcan): New built-in.
(syms_of_fns): Define.
* lisp/emacs-lisp/cl.el (mapcan): Remove defalias.
* lisp/emacs-lisp/cl-extra.el (cl-mapcan): Use built-in `mapcan'
if only one sequence is provided.
* lisp/progmodes/hideif.el (hif-delimit):
* lisp/dired-aux.el (dired-do-find-regexp):
* lisp/woman.el (woman-parse-colon-path): Use `mapcan' instead of
`cl-mapcan'.
* lisp/woman.el (eval-when-compile): Require 'cl-lib only when
compiling.
* lisp/mouse.el (mouse-buffer-menu-map):
* lisp/net/pop3.el (pop3-uidl-dele):
* lisp/progmodes/gud.el (gud-jdb-build-source-files-list):
* lisp/cedet/semantic/db-find.el (semanticdb-fast-strip-find-results):
* lisp/cedet/semantic/symref/grep.el (semantic-symref-derive-find-filepatterns):
* lisp/gnus/nnmail.el (nnmail-split-it):
* lisp/gnus/gnus-sum.el (gnus-articles-in-thread):
* lisp/gnus/gnus-registry.el (gnus-registry-sort-addresses):
* lisp/gnus/gnus-util.el (gnus-mapcar): Use `mapcan'.
Diffstat (limited to 'src')
| -rw-r--r-- | src/fns.c | 25 |
1 files changed, 25 insertions, 0 deletions
| @@ -2654,6 +2654,30 @@ SEQUENCE may be a list, a vector, a bool-vector, or a string. */) | |||
| 2654 | 2654 | ||
| 2655 | return sequence; | 2655 | return sequence; |
| 2656 | } | 2656 | } |
| 2657 | |||
| 2658 | DEFUN ("mapcan", Fmapcan, Smapcan, 2, 2, 0, | ||
| 2659 | doc: /* Apply FUNCTION to each element of SEQUENCE, and concatenate | ||
| 2660 | the results by altering them (using `nconc'). | ||
| 2661 | SEQUENCE may be a list, a vector, a bool-vector, or a string. */) | ||
| 2662 | (Lisp_Object function, Lisp_Object sequence) | ||
| 2663 | { | ||
| 2664 | register EMACS_INT leni; | ||
| 2665 | register Lisp_Object *args; | ||
| 2666 | Lisp_Object ret; | ||
| 2667 | USE_SAFE_ALLOCA; | ||
| 2668 | |||
| 2669 | if (CHAR_TABLE_P (sequence)) | ||
| 2670 | wrong_type_argument (Qlistp, sequence); | ||
| 2671 | |||
| 2672 | leni = XFASTINT (Flength (sequence)); | ||
| 2673 | SAFE_ALLOCA_LISP (args, leni); | ||
| 2674 | mapcar1 (leni, args, function, sequence); | ||
| 2675 | ret = Fnconc (leni, args); | ||
| 2676 | |||
| 2677 | SAFE_FREE (); | ||
| 2678 | |||
| 2679 | return ret; | ||
| 2680 | } | ||
| 2657 | 2681 | ||
| 2658 | /* This is how C code calls `yes-or-no-p' and allows the user | 2682 | /* This is how C code calls `yes-or-no-p' and allows the user |
| 2659 | to redefine it. */ | 2683 | to redefine it. */ |
| @@ -5203,6 +5227,7 @@ this variable. */); | |||
| 5203 | defsubr (&Snconc); | 5227 | defsubr (&Snconc); |
| 5204 | defsubr (&Smapcar); | 5228 | defsubr (&Smapcar); |
| 5205 | defsubr (&Smapc); | 5229 | defsubr (&Smapc); |
| 5230 | defsubr (&Smapcan); | ||
| 5206 | defsubr (&Smapconcat); | 5231 | defsubr (&Smapconcat); |
| 5207 | defsubr (&Syes_or_no_p); | 5232 | defsubr (&Syes_or_no_p); |
| 5208 | defsubr (&Sload_average); | 5233 | defsubr (&Sload_average); |