aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorDmitry Antipov2015-01-16 11:42:24 +0300
committerDmitry Antipov2015-01-16 11:42:24 +0300
commit3b48f99542d822c0647334524035e93f4a094358 (patch)
tree8d743237c2a211fca50dee6d93cb58a11a976d68 /src
parent0ecb1eb988d25d3511e11ac39e05550cec57dc3f (diff)
downloademacs-3b48f99542d822c0647334524035e93f4a094358.tar.gz
emacs-3b48f99542d822c0647334524035e93f4a094358.zip
Tune pseudovector allocation assuming Qnil == 0
* alloc.c (allocate_pseudovector): Use memset for both Lisp_Objects and regular slots. Add zerolen arg. * lisp.h (allocate_pseudovector): Adjust prototype. (ALLOCATE_PSEUDOVECTOR): Adjust user. (ALLOCATE_ZEROED_PSEUDOVECTOR): New macro. (allocate_hash_table, allocate_window, allocate_frame) (allocate_process, allocate_terminal): Remove prototypes. * fns.c (allocate_hash_table): Now static here. * frame.c (allocate_frame): * process.c (allocate_process): * terminal.c (allocate_terminal): * window.c (allocate_window): Now static here. Use ALLOCATE_ZEROED_PSEUDOVECTOR. Add comment.
Diffstat (limited to 'src')
-rw-r--r--src/ChangeLog17
-rw-r--r--src/alloc.c64
-rw-r--r--src/fns.c9
-rw-r--r--src/font.c7
-rw-r--r--src/frame.c7
-rw-r--r--src/lisp.h29
-rw-r--r--src/process.c10
-rw-r--r--src/terminal.c9
-rw-r--r--src/window.c11
9 files changed, 89 insertions, 74 deletions
diff --git a/src/ChangeLog b/src/ChangeLog
index ae634f318f0..63da5cbd972 100644
--- a/src/ChangeLog
+++ b/src/ChangeLog
@@ -1,3 +1,20 @@
12015-01-16 Dmitry Antipov <dmantipov@yandex.ru>
2
3 Tune pseudovector allocation assuming Qnil == 0.
4 * alloc.c (allocate_pseudovector): Use memset for both
5 Lisp_Objects and regular slots. Add zerolen arg.
6 * lisp.h (allocate_pseudovector): Adjust prototype.
7 (ALLOCATE_PSEUDOVECTOR): Adjust user.
8 (ALLOCATE_ZEROED_PSEUDOVECTOR): New macro.
9 (allocate_hash_table, allocate_window, allocate_frame)
10 (allocate_process, allocate_terminal): Remove prototypes.
11 * fns.c (allocate_hash_table): Now static here.
12 * frame.c (allocate_frame):
13 * process.c (allocate_process):
14 * terminal.c (allocate_terminal):
15 * window.c (allocate_window): Now static here.
16 Use ALLOCATE_ZEROED_PSEUDOVECTOR. Add comment.
17
12015-01-16 Paul Eggert <eggert@cs.ucla.edu> 182015-01-16 Paul Eggert <eggert@cs.ucla.edu>
2 19
3 Give up on -Wsuggest-attribute=const 20 Give up on -Wsuggest-attribute=const
diff --git a/src/alloc.c b/src/alloc.c
index 7c937332407..22a15b4ac59 100644
--- a/src/alloc.c
+++ b/src/alloc.c
@@ -3163,19 +3163,19 @@ allocate_vector (EMACS_INT len)
3163/* Allocate other vector-like structures. */ 3163/* Allocate other vector-like structures. */
3164 3164
3165struct Lisp_Vector * 3165struct Lisp_Vector *
3166allocate_pseudovector (int memlen, int lisplen, enum pvec_type tag) 3166allocate_pseudovector (int memlen, int lisplen,
3167 int zerolen, enum pvec_type tag)
3167{ 3168{
3168 struct Lisp_Vector *v = allocate_vectorlike (memlen); 3169 struct Lisp_Vector *v = allocate_vectorlike (memlen);
3169 int i;
3170 3170
3171 /* Catch bogus values. */ 3171 /* Catch bogus values. */
3172 eassert (tag <= PVEC_FONT); 3172 eassert (tag <= PVEC_FONT);
3173 eassert (memlen - lisplen <= (1 << PSEUDOVECTOR_REST_BITS) - 1); 3173 eassert (memlen - lisplen <= (1 << PSEUDOVECTOR_REST_BITS) - 1);
3174 eassert (lisplen <= (1 << PSEUDOVECTOR_SIZE_BITS) - 1); 3174 eassert (lisplen <= (1 << PSEUDOVECTOR_SIZE_BITS) - 1);
3175 3175
3176 /* Only the first lisplen slots will be traced normally by the GC. */ 3176 /* Only the first lisplen slots will be traced normally by the GC.
3177 for (i = 0; i < lisplen; ++i) 3177 But since Qnil == 0, we can memset Lisp_Object slots as well. */
3178 v->contents[i] = Qnil; 3178 memset (v->contents, 0, zerolen * word_size);
3179 3179
3180 XSETPVECTYPESIZE (v, tag, lisplen, memlen - lisplen); 3180 XSETPVECTYPESIZE (v, tag, lisplen, memlen - lisplen);
3181 return v; 3181 return v;
@@ -3194,60 +3194,6 @@ allocate_buffer (void)
3194 return b; 3194 return b;
3195} 3195}
3196 3196
3197struct Lisp_Hash_Table *
3198allocate_hash_table (void)
3199{
3200 return ALLOCATE_PSEUDOVECTOR (struct Lisp_Hash_Table, count, PVEC_HASH_TABLE);
3201}
3202
3203struct window *
3204allocate_window (void)
3205{
3206 struct window *w;
3207
3208 w = ALLOCATE_PSEUDOVECTOR (struct window, current_matrix, PVEC_WINDOW);
3209 /* Users assumes that non-Lisp data is zeroed. */
3210 memset (&w->current_matrix, 0,
3211 sizeof (*w) - offsetof (struct window, current_matrix));
3212 return w;
3213}
3214
3215struct terminal *
3216allocate_terminal (void)
3217{
3218 struct terminal *t;
3219
3220 t = ALLOCATE_PSEUDOVECTOR (struct terminal, next_terminal, PVEC_TERMINAL);
3221 /* Users assumes that non-Lisp data is zeroed. */
3222 memset (&t->next_terminal, 0,
3223 sizeof (*t) - offsetof (struct terminal, next_terminal));
3224 return t;
3225}
3226
3227struct frame *
3228allocate_frame (void)
3229{
3230 struct frame *f;
3231
3232 f = ALLOCATE_PSEUDOVECTOR (struct frame, face_cache, PVEC_FRAME);
3233 /* Users assumes that non-Lisp data is zeroed. */
3234 memset (&f->face_cache, 0,
3235 sizeof (*f) - offsetof (struct frame, face_cache));
3236 return f;
3237}
3238
3239struct Lisp_Process *
3240allocate_process (void)
3241{
3242 struct Lisp_Process *p;
3243
3244 p = ALLOCATE_PSEUDOVECTOR (struct Lisp_Process, pid, PVEC_PROCESS);
3245 /* Users assumes that non-Lisp data is zeroed. */
3246 memset (&p->pid, 0,
3247 sizeof (*p) - offsetof (struct Lisp_Process, pid));
3248 return p;
3249}
3250
3251DEFUN ("make-vector", Fmake_vector, Smake_vector, 2, 2, 0, 3197DEFUN ("make-vector", Fmake_vector, Smake_vector, 2, 2, 0,
3252 doc: /* Return a newly created vector of length LENGTH, with each element being INIT. 3198 doc: /* Return a newly created vector of length LENGTH, with each element being INIT.
3253See also the function `vector'. */) 3199See also the function `vector'. */)
diff --git a/src/fns.c b/src/fns.c
index 91cd5132546..ca3d98b23dd 100644
--- a/src/fns.c
+++ b/src/fns.c
@@ -3814,6 +3814,15 @@ hashfn_user_defined (struct hash_table_test *ht, Lisp_Object key)
3814 return hashfn_eq (ht, hash); 3814 return hashfn_eq (ht, hash);
3815} 3815}
3816 3816
3817/* Allocate basically initialized hash table. */
3818
3819static struct Lisp_Hash_Table *
3820allocate_hash_table (void)
3821{
3822 return ALLOCATE_PSEUDOVECTOR (struct Lisp_Hash_Table,
3823 count, PVEC_HASH_TABLE);
3824}
3825
3817/* An upper bound on the size of a hash table index. It must fit in 3826/* An upper bound on the size of a hash table index. It must fit in
3818 ptrdiff_t and be a valid Emacs fixnum. */ 3827 ptrdiff_t and be a valid Emacs fixnum. */
3819#define INDEX_SIZE_BOUND \ 3828#define INDEX_SIZE_BOUND \
diff --git a/src/font.c b/src/font.c
index a68c3c707c8..074e86687a1 100644
--- a/src/font.c
+++ b/src/font.c
@@ -156,7 +156,7 @@ font_make_spec (void)
156 struct font_spec *spec 156 struct font_spec *spec
157 = ((struct font_spec *) 157 = ((struct font_spec *)
158 allocate_pseudovector (VECSIZE (struct font_spec), 158 allocate_pseudovector (VECSIZE (struct font_spec),
159 FONT_SPEC_MAX, PVEC_FONT)); 159 FONT_SPEC_MAX, FONT_SPEC_MAX, PVEC_FONT));
160 XSETFONT (font_spec, spec); 160 XSETFONT (font_spec, spec);
161 return font_spec; 161 return font_spec;
162} 162}
@@ -168,7 +168,7 @@ font_make_entity (void)
168 struct font_entity *entity 168 struct font_entity *entity
169 = ((struct font_entity *) 169 = ((struct font_entity *)
170 allocate_pseudovector (VECSIZE (struct font_entity), 170 allocate_pseudovector (VECSIZE (struct font_entity),
171 FONT_ENTITY_MAX, PVEC_FONT)); 171 FONT_ENTITY_MAX, FONT_ENTITY_MAX, PVEC_FONT));
172 XSETFONT (font_entity, entity); 172 XSETFONT (font_entity, entity);
173 return font_entity; 173 return font_entity;
174} 174}
@@ -181,7 +181,8 @@ font_make_object (int size, Lisp_Object entity, int pixelsize)
181{ 181{
182 Lisp_Object font_object; 182 Lisp_Object font_object;
183 struct font *font 183 struct font *font
184 = (struct font *) allocate_pseudovector (size, FONT_OBJECT_MAX, PVEC_FONT); 184 = (struct font *) allocate_pseudovector (size, FONT_OBJECT_MAX,
185 FONT_OBJECT_MAX, PVEC_FONT);
185 int i; 186 int i;
186 187
187 /* GC can happen before the driver is set up, 188 /* GC can happen before the driver is set up,
diff --git a/src/frame.c b/src/frame.c
index ec580f37c5b..2ce5a623853 100644
--- a/src/frame.c
+++ b/src/frame.c
@@ -570,6 +570,13 @@ adjust_frame_size (struct frame *f, int new_width, int new_height, int inhibit,
570 run_window_configuration_change_hook (f); 570 run_window_configuration_change_hook (f);
571} 571}
572 572
573/* Allocate basically initialized frame. */
574
575static struct frame *
576allocate_frame (void)
577{
578 return ALLOCATE_ZEROED_PSEUDOVECTOR (struct frame, face_cache, PVEC_FRAME);
579}
573 580
574struct frame * 581struct frame *
575make_frame (bool mini_p) 582make_frame (bool mini_p)
diff --git a/src/lisp.h b/src/lisp.h
index 51556fcc91c..fd0a0342cf8 100644
--- a/src/lisp.h
+++ b/src/lisp.h
@@ -3780,16 +3780,25 @@ make_uninit_sub_char_table (int depth, int min_char)
3780 return v; 3780 return v;
3781} 3781}
3782 3782
3783extern struct Lisp_Vector *allocate_pseudovector (int, int, enum pvec_type); 3783extern struct Lisp_Vector *allocate_pseudovector (int, int, int,
3784#define ALLOCATE_PSEUDOVECTOR(typ,field,tag) \ 3784 enum pvec_type);
3785 ((typ*) \ 3785
3786 allocate_pseudovector \ 3786/* Allocate partially initialized pseudovector where all Lisp_Object
3787 (VECSIZE (typ), PSEUDOVECSIZE (typ, field), tag)) 3787 slots are set to Qnil but the rest (if any) is left uninitialized. */
3788extern struct Lisp_Hash_Table *allocate_hash_table (void); 3788
3789extern struct window *allocate_window (void); 3789#define ALLOCATE_PSEUDOVECTOR(type, field, tag) \
3790extern struct frame *allocate_frame (void); 3790 ((type *) allocate_pseudovector (VECSIZE (type), \
3791extern struct Lisp_Process *allocate_process (void); 3791 PSEUDOVECSIZE (type, field), \
3792extern struct terminal *allocate_terminal (void); 3792 PSEUDOVECSIZE (type, field), tag))
3793
3794/* Allocate fully initialized pseudovector where all Lisp_Object
3795 slots are set to Qnil and the rest (if any) is zeroed. */
3796
3797#define ALLOCATE_ZEROED_PSEUDOVECTOR(type, field, tag) \
3798 ((type *) allocate_pseudovector (VECSIZE (type), \
3799 PSEUDOVECSIZE (type, field), \
3800 VECSIZE (type), tag))
3801
3793extern bool gc_in_progress; 3802extern bool gc_in_progress;
3794extern bool abort_on_gc; 3803extern bool abort_on_gc;
3795extern Lisp_Object make_float (double); 3804extern Lisp_Object make_float (double);
diff --git a/src/process.c b/src/process.c
index 77c94f29211..30380548210 100644
--- a/src/process.c
+++ b/src/process.c
@@ -687,7 +687,15 @@ allocate_pty (char pty_name[PTY_NAME_SIZE])
687#endif /* HAVE_PTYS */ 687#endif /* HAVE_PTYS */
688 return -1; 688 return -1;
689} 689}
690 690
691/* Allocate basically initialized process. */
692
693static struct Lisp_Process *
694allocate_process (void)
695{
696 return ALLOCATE_ZEROED_PSEUDOVECTOR (struct Lisp_Process, pid, PVEC_PROCESS);
697}
698
691static Lisp_Object 699static Lisp_Object
692make_process (Lisp_Object name) 700make_process (Lisp_Object name)
693{ 701{
diff --git a/src/terminal.c b/src/terminal.c
index 92befd28543..b48d0623e12 100644
--- a/src/terminal.c
+++ b/src/terminal.c
@@ -254,6 +254,15 @@ get_named_terminal (const char *name)
254 return NULL; 254 return NULL;
255} 255}
256 256
257/* Allocate basically initialized terminal. */
258
259static struct terminal *
260allocate_terminal (void)
261{
262 return ALLOCATE_ZEROED_PSEUDOVECTOR
263 (struct terminal, next_terminal, PVEC_TERMINAL);
264}
265
257/* Create a new terminal object of TYPE and add it to the terminal list. RIF 266/* Create a new terminal object of TYPE and add it to the terminal list. RIF
258 may be NULL if this terminal type doesn't support window-based redisplay. */ 267 may be NULL if this terminal type doesn't support window-based redisplay. */
259 268
diff --git a/src/window.c b/src/window.c
index e5ddef5fa40..53a235f8446 100644
--- a/src/window.c
+++ b/src/window.c
@@ -3642,7 +3642,16 @@ temp_output_buffer_show (register Lisp_Object buf)
3642 } 3642 }
3643 } 3643 }
3644} 3644}
3645 3645
3646/* Allocate basically initialized window. */
3647
3648static struct window *
3649allocate_window (void)
3650{
3651 return ALLOCATE_ZEROED_PSEUDOVECTOR
3652 (struct window, current_matrix, PVEC_WINDOW);
3653}
3654
3646/* Make new window, have it replace WINDOW in window-tree, and make 3655/* Make new window, have it replace WINDOW in window-tree, and make
3647 WINDOW its only vertical child (HORFLAG 1 means make WINDOW its only 3656 WINDOW its only vertical child (HORFLAG 1 means make WINDOW its only
3648 horizontal child). */ 3657 horizontal child). */