diff options
| author | Dmitry Antipov | 2015-01-16 11:42:24 +0300 |
|---|---|---|
| committer | Dmitry Antipov | 2015-01-16 11:42:24 +0300 |
| commit | 3b48f99542d822c0647334524035e93f4a094358 (patch) | |
| tree | 8d743237c2a211fca50dee6d93cb58a11a976d68 /src/alloc.c | |
| parent | 0ecb1eb988d25d3511e11ac39e05550cec57dc3f (diff) | |
| download | emacs-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/alloc.c')
| -rw-r--r-- | src/alloc.c | 64 |
1 files changed, 5 insertions, 59 deletions
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 | ||
| 3165 | struct Lisp_Vector * | 3165 | struct Lisp_Vector * |
| 3166 | allocate_pseudovector (int memlen, int lisplen, enum pvec_type tag) | 3166 | allocate_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 | ||
| 3197 | struct Lisp_Hash_Table * | ||
| 3198 | allocate_hash_table (void) | ||
| 3199 | { | ||
| 3200 | return ALLOCATE_PSEUDOVECTOR (struct Lisp_Hash_Table, count, PVEC_HASH_TABLE); | ||
| 3201 | } | ||
| 3202 | |||
| 3203 | struct window * | ||
| 3204 | allocate_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 | |||
| 3215 | struct terminal * | ||
| 3216 | allocate_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 | |||
| 3227 | struct frame * | ||
| 3228 | allocate_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 | |||
| 3239 | struct Lisp_Process * | ||
| 3240 | allocate_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 | |||
| 3251 | DEFUN ("make-vector", Fmake_vector, Smake_vector, 2, 2, 0, | 3197 | DEFUN ("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. |
| 3253 | See also the function `vector'. */) | 3199 | See also the function `vector'. */) |