aboutsummaryrefslogtreecommitdiffstats
path: root/src/alloc.c
diff options
context:
space:
mode:
authorPaul Eggert2019-03-04 00:00:39 -0800
committerPaul Eggert2019-03-04 00:05:04 -0800
commit5c2563a5472cd5580e7af570aa320ac581ad1985 (patch)
treefbf88ede49dc0ba527d3925dfc274c230b8cf95f /src/alloc.c
parentd6b3e5bbc5e14c32f3faad9f1481ec16807ac2fe (diff)
downloademacs-5c2563a5472cd5580e7af570aa320ac581ad1985.tar.gz
emacs-5c2563a5472cd5580e7af570aa320ac581ad1985.zip
Simplify list creation in C code
The main new thing here is that C code can now say ‘list (a, b, c, d, e, f)’ instead of ‘listn (CONSTYPE_HEAP, 6, a, b, c, d, e, f)’, thus relieving callers of the responsibility of counting arguments (plus, the code feels more like Lisp). The old list1 ... list5 functions remain, as they’re probably a bit faster for small lists. * src/alloc.c (cons_listn, pure_listn): New functions. (listn): Omit enum argument. All callers changed to use either new ‘list’ or ‘pure_list’ macros. * src/charset.c (Fdefine_charset_internal): * src/coding.c (detect_coding_system) (Fset_terminal_coding_system_internal): * src/frame.c (frame_size_history_add, adjust_frame_size): * src/gtkutil.c (xg_frame_set_char_size): * src/keyboard.c (command_loop_1): * src/nsfns.m (frame_geometry): * src/widget.c (set_frame_size): * src/xfaces.c (Fcolor_distance): * src/xfns.c (frame_geometry): * src/xterm.c (x_set_window_size_1): * src/xwidget.c (Fxwidget_size_request): Prefer list1i, list2i, etc. to open-coding them. * src/charset.c (Fset_charset_priority): * src/nsterm.m (append2): * src/window.c (window_list): * src/xfaces.c (Fx_list_fonts): Use nconc2 instead of open-coding it. * src/eval.c (eval_sub, backtrace_frame_apply): * src/kqueue.c (kqueue_generate_event): * src/nsterm.m (performDragOperation:): * src/pdumper.c (Fpdumper_stats): * src/w32.c (init_environment): Prefer list1, list2, etc. to open-coding them. * src/font.c (font_list_entities): Parenthesize to avoid expanding new ‘list’ macro. * src/gtkutil.c (GETSETUP): Rename from MAKE_FLOAT_PAGE_SETUP to get lines to fit. Move outside the ‘list’ call, since it’s now a macro. * src/keymap.c (Fmake_keymap): Simplify. * src/lisp.h (list, pure_list): New macros. (list1i): New function.
Diffstat (limited to 'src/alloc.c')
-rw-r--r--src/alloc.c56
1 files changed, 32 insertions, 24 deletions
diff --git a/src/alloc.c b/src/alloc.c
index 6b366485550..02c55f8ce4c 100644
--- a/src/alloc.c
+++ b/src/alloc.c
@@ -2864,50 +2864,57 @@ list3 (Lisp_Object arg1, Lisp_Object arg2, Lisp_Object arg3)
2864 return Fcons (arg1, Fcons (arg2, Fcons (arg3, Qnil))); 2864 return Fcons (arg1, Fcons (arg2, Fcons (arg3, Qnil)));
2865} 2865}
2866 2866
2867
2868Lisp_Object 2867Lisp_Object
2869list4 (Lisp_Object arg1, Lisp_Object arg2, Lisp_Object arg3, Lisp_Object arg4) 2868list4 (Lisp_Object arg1, Lisp_Object arg2, Lisp_Object arg3, Lisp_Object arg4)
2870{ 2869{
2871 return Fcons (arg1, Fcons (arg2, Fcons (arg3, Fcons (arg4, Qnil)))); 2870 return Fcons (arg1, Fcons (arg2, Fcons (arg3, Fcons (arg4, Qnil))));
2872} 2871}
2873 2872
2874
2875Lisp_Object 2873Lisp_Object
2876list5 (Lisp_Object arg1, Lisp_Object arg2, Lisp_Object arg3, Lisp_Object arg4, Lisp_Object arg5) 2874list5 (Lisp_Object arg1, Lisp_Object arg2, Lisp_Object arg3, Lisp_Object arg4,
2875 Lisp_Object arg5)
2877{ 2876{
2878 return Fcons (arg1, Fcons (arg2, Fcons (arg3, Fcons (arg4, 2877 return Fcons (arg1, Fcons (arg2, Fcons (arg3, Fcons (arg4,
2879 Fcons (arg5, Qnil))))); 2878 Fcons (arg5, Qnil)))));
2880} 2879}
2881 2880
2882/* Make a list of COUNT Lisp_Objects, where ARG is the 2881/* Make a list of COUNT Lisp_Objects, where ARG is the first one.
2883 first one. Allocate conses from pure space if TYPE 2882 Use CONS to construct the pairs. AP has any remaining args. */
2884 is CONSTYPE_PURE, or allocate as usual if type is CONSTYPE_HEAP. */ 2883static Lisp_Object
2885 2884cons_listn (ptrdiff_t count, Lisp_Object arg,
2886Lisp_Object 2885 Lisp_Object (*cons) (Lisp_Object, Lisp_Object), va_list ap)
2887listn (enum constype type, ptrdiff_t count, Lisp_Object arg, ...)
2888{ 2886{
2889 Lisp_Object (*cons) (Lisp_Object, Lisp_Object);
2890 switch (type)
2891 {
2892 case CONSTYPE_PURE: cons = pure_cons; break;
2893 case CONSTYPE_HEAP: cons = Fcons; break;
2894 default: emacs_abort ();
2895 }
2896
2897 eassume (0 < count); 2887 eassume (0 < count);
2898 Lisp_Object val = cons (arg, Qnil); 2888 Lisp_Object val = cons (arg, Qnil);
2899 Lisp_Object tail = val; 2889 Lisp_Object tail = val;
2900
2901 va_list ap;
2902 va_start (ap, arg);
2903 for (ptrdiff_t i = 1; i < count; i++) 2890 for (ptrdiff_t i = 1; i < count; i++)
2904 { 2891 {
2905 Lisp_Object elem = cons (va_arg (ap, Lisp_Object), Qnil); 2892 Lisp_Object elem = cons (va_arg (ap, Lisp_Object), Qnil);
2906 XSETCDR (tail, elem); 2893 XSETCDR (tail, elem);
2907 tail = elem; 2894 tail = elem;
2908 } 2895 }
2896 return val;
2897}
2898
2899/* Make a list of COUNT Lisp_Objects, where ARG1 is the first one. */
2900Lisp_Object
2901listn (ptrdiff_t count, Lisp_Object arg1, ...)
2902{
2903 va_list ap;
2904 va_start (ap, arg1);
2905 Lisp_Object val = cons_listn (count, arg1, Fcons, ap);
2909 va_end (ap); 2906 va_end (ap);
2907 return val;
2908}
2910 2909
2910/* Make a pure list of COUNT Lisp_Objects, where ARG1 is the first one. */
2911Lisp_Object
2912pure_listn (ptrdiff_t count, Lisp_Object arg1, ...)
2913{
2914 va_list ap;
2915 va_start (ap, arg1);
2916 Lisp_Object val = cons_listn (count, arg1, pure_cons, ap);
2917 va_end (ap);
2911 return val; 2918 return val;
2912} 2919}
2913 2920
@@ -7283,8 +7290,7 @@ Frames, windows, buffers, and subprocesses count as vectors
7283 (but the contents of a buffer's text do not count here). */) 7290 (but the contents of a buffer's text do not count here). */)
7284 (void) 7291 (void)
7285{ 7292{
7286 return listn (CONSTYPE_HEAP, 7, 7293 return list (make_int (cons_cells_consed),
7287 make_int (cons_cells_consed),
7288 make_int (floats_consed), 7294 make_int (floats_consed),
7289 make_int (vector_cells_consed), 7295 make_int (vector_cells_consed),
7290 make_int (symbols_consed), 7296 make_int (symbols_consed),
@@ -7584,8 +7590,10 @@ do hash-consing of the objects allocated to pure space. */);
7584 /* We build this in advance because if we wait until we need it, we might 7590 /* We build this in advance because if we wait until we need it, we might
7585 not be able to allocate the memory to hold it. */ 7591 not be able to allocate the memory to hold it. */
7586 Vmemory_signal_data 7592 Vmemory_signal_data
7587 = listn (CONSTYPE_PURE, 2, Qerror, 7593 = pure_list (Qerror,
7588 build_pure_c_string ("Memory exhausted--use M-x save-some-buffers then exit and restart Emacs")); 7594 build_pure_c_string ("Memory exhausted--use"
7595 " M-x save-some-buffers then"
7596 " exit and restart Emacs"));
7589 7597
7590 DEFVAR_LISP ("memory-full", Vmemory_full, 7598 DEFVAR_LISP ("memory-full", Vmemory_full,
7591 doc: /* Non-nil means Emacs cannot get much more Lisp memory. */); 7599 doc: /* Non-nil means Emacs cannot get much more Lisp memory. */);