From f135e94e4ecb4c6d3f88c7e028c935c2858f2e02 Mon Sep 17 00:00:00 2001 From: Paul Eggert Date: Sun, 21 Sep 2014 15:49:24 -0700 Subject: [PATCH] Minor improvements to new stack-allocated Lisp objects. * frame.h (FRAME_PARAMETER): Prefer scoped_list1 to local_list1 where either would do. * lisp.h (scoped_list4): New macro. (local_cons, local_list1, local_list2, local_list3, local_list4) (make_local_vector, make_local_string, build_local_string): Prefer functions to macros where either would do. * xdisp.c (build_desired_tool_bar_string): Prefer scoped_list4 to local_list4 where either would do. --- src/ChangeLog | 12 +++++++++ src/frame.h | 2 +- src/lisp.h | 70 ++++++++++++++++++++++++++++++++++++++------------- src/xdisp.c | 21 ++++++++++------ 4 files changed, 79 insertions(+), 26 deletions(-) diff --git a/src/ChangeLog b/src/ChangeLog index 0e676e2c73c..a80394b5855 100644 --- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,3 +1,15 @@ +2014-09-21 Paul Eggert + + Minor improvements to new stack-allocated Lisp objects. + * frame.h (FRAME_PARAMETER): + Prefer scoped_list1 to local_list1 where either would do. + * lisp.h (scoped_list4): New macro. + (local_cons, local_list1, local_list2, local_list3, local_list4) + (make_local_vector, make_local_string, build_local_string): + Prefer functions to macros where either would do. + * xdisp.c (build_desired_tool_bar_string): + Prefer scoped_list4 to local_list4 where either would do. + 2014-09-18 Dmitry Antipov More and more stack-allocated Lisp objects if USE_LOCAL_ALLOCATORS. diff --git a/src/frame.h b/src/frame.h index 0ba3e3712f6..94f080d3038 100644 --- a/src/frame.h +++ b/src/frame.h @@ -1063,7 +1063,7 @@ default_pixels_per_inch_y (void) /* Handy macro to construct an argument to Fmodify_frame_parameters. */ #define FRAME_PARAMETER(parameter, value) \ - local_list1 (scoped_cons (parameter, value)) + scoped_list1 (scoped_cons (parameter, value)) /* False means there are no visible garbaged frames. */ extern bool frame_garbaged; diff --git a/src/lisp.h b/src/lisp.h index b8e75f90ef5..1347b35f046 100644 --- a/src/lisp.h +++ b/src/lisp.h @@ -4590,13 +4590,15 @@ verify (sizeof (struct Lisp_Cons) == sizeof (union Aligned_Cons)); /* Convenient utility macros similar to listX functions. */ #if USE_STACK_LISP_OBJECTS -# define scoped_list1(x) scoped_cons (x, Qnil) -# define scoped_list2(x, y) scoped_cons (x, scoped_list1 (y)) -# define scoped_list3(x, y, z) scoped_cons (x, scoped_list2 (y, z)) +# define scoped_list1(a) scoped_cons (a, Qnil) +# define scoped_list2(a, b) scoped_cons (a, scoped_list1 (b)) +# define scoped_list3(a, b, c) scoped_cons (a, scoped_list2 (b, c)) +# define scoped_list4(a, b, c, d) scoped_cons (a, scoped_list3 (b, c, d)) #else -# define scoped_list1(x) list1 (x) -# define scoped_list2(x, y) list2 (x, y) -# define scoped_list3(x, y, z) list3 (x, y, z) +# define scoped_list1(a) list1 (a) +# define scoped_list2(a, b) list2 (a, b) +# define scoped_list3(a, b, c) list3 (a, b, c) +# define scoped_list4(a, b, c, d) list4 (a, b, c, d) #endif /* Local allocators require both statement expressions and a @@ -4620,10 +4622,10 @@ verify (sizeof (struct Lisp_Cons) == sizeof (union Aligned_Cons)); make_lisp_ptr (c_, Lisp_Cons); \ }) -# define local_list1(x) local_cons (x, Qnil) -# define local_list2(x, y) local_cons (x, local_list1 (y)) -# define local_list3(x, y, z) local_cons (x, local_list2 (y, z)) -# define local_list4(x, y, z, t) local_cons (x, local_list3 (y, z, t)) +# define local_list1(a) local_cons (a, Qnil) +# define local_list2(a, b) local_cons (a, local_list1 (b)) +# define local_list3(a, b, c) local_cons (a, local_list2 (b, c)) +# define local_list4(a, b, c, d) local_cons (a, local_list3 (b, c, d)) /* Return a function-scoped vector of length SIZE, with each element being INIT. */ @@ -4670,14 +4672,46 @@ verify (sizeof (struct Lisp_Cons) == sizeof (union Aligned_Cons)); #else /* Safer but slower implementations. */ -# define local_cons(car, cdr) Fcons (car, cdr) -# define local_list1(x) list1 (x) -# define local_list2(x, y) list2 (x, y) -# define local_list3(x, y, z) list3 (x, y, z) -# define local_list4(x, y, z, t) list4 (x, y, z, t) -# define make_local_vector(size, init) Fmake_vector (make_number (size), init) -# define make_local_string(data, nbytes) make_string (data, nbytes) -# define build_local_string(data) build_string (data) +INLINE Lisp_Object +local_cons (Lisp_Object car, Lisp_Object cdr) +{ + return Fcons (car, cdr); +} +INLINE Lisp_Object +local_list1 (Lisp_Object a) +{ + return list1 (a); +} +INLINE Lisp_Object +local_list2 (Lisp_Object a, Lisp_Object b) +{ + return list2 (a, b); +} +INLINE Lisp_Object +local_list3 (Lisp_Object a, Lisp_Object b, Lisp_Object c) +{ + return list3 (a, b, c); +} +INLINE Lisp_Object +local_list4 (Lisp_Object a, Lisp_Object b, Lisp_Object c, Lisp_Object d) +{ + return list4 (a, b, c, d); +} +INLINE Lisp_Object +make_local_vector (ptrdiff_t size, Lisp_Object init) +{ + return Fmake_vector (make_number (size), init); +} +INLINE Lisp_Object +make_local_string (char const *str, ptrdiff_t nbytes) +{ + return make_string (str, nbytes); +} +INLINE Lisp_Object +build_local_string (const char *str) +{ + return build_string (str); +} #endif diff --git a/src/xdisp.c b/src/xdisp.c index a35cac35e60..08b7154aa8b 100644 --- a/src/xdisp.c +++ b/src/xdisp.c @@ -12038,11 +12038,11 @@ static void build_desired_tool_bar_string (struct frame *f) { int i, size, size_needed; - struct gcpro gcpro1, gcpro2, gcpro3; - Lisp_Object image, plist, props; + struct gcpro gcpro1, gcpro2; + Lisp_Object image, plist; - image = plist = props = Qnil; - GCPRO3 (image, plist, props); + image = plist = Qnil; + GCPRO2 (image, plist); /* Prepare F->desired_tool_bar_string. If we can reuse it, do so. Otherwise, make a new string. */ @@ -12061,9 +12061,12 @@ build_desired_tool_bar_string (struct frame *f) (f, Fmake_string (make_number (size_needed), make_number (' '))); else { - props = local_list4 (Qdisplay, Qnil, Qmenu_item, Qnil); + Lisp_Object props = scoped_list4 (Qdisplay, Qnil, Qmenu_item, Qnil); + struct gcpro gcpro1; + GCPRO1 (props); Fremove_text_properties (make_number (0), make_number (size), props, f->desired_tool_bar_string); + UNGCPRO; } /* Put a `display' property on the string for the images to display, @@ -12174,8 +12177,11 @@ build_desired_tool_bar_string (struct frame *f) the start of this item's properties in the tool-bar items vector. */ image = Fcons (Qimage, plist); - props = local_list4 (Qdisplay, image, Qmenu_item, - make_number (i * TOOL_BAR_ITEM_NSLOTS)); + Lisp_Object props + = scoped_list4 (Qdisplay, image, Qmenu_item, + make_number (i * TOOL_BAR_ITEM_NSLOTS)); + struct gcpro gcpro1; + GCPRO1 (props); /* Let the last image hide all remaining spaces in the tool bar string. The string can be longer than needed when we reuse a @@ -12186,6 +12192,7 @@ build_desired_tool_bar_string (struct frame *f) end = i + 1; Fadd_text_properties (make_number (i), make_number (end), props, f->desired_tool_bar_string); + UNGCPRO; #undef PROP } -- 2.39.5