+2015-01-16 Dmitry Antipov <dmantipov@yandex.ru>
+
+ 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.
+
2015-01-16 Paul Eggert <eggert@cs.ucla.edu>
Give up on -Wsuggest-attribute=const
/* Allocate other vector-like structures. */
struct Lisp_Vector *
-allocate_pseudovector (int memlen, int lisplen, enum pvec_type tag)
+allocate_pseudovector (int memlen, int lisplen,
+ int zerolen, enum pvec_type tag)
{
struct Lisp_Vector *v = allocate_vectorlike (memlen);
- int i;
/* Catch bogus values. */
eassert (tag <= PVEC_FONT);
eassert (memlen - lisplen <= (1 << PSEUDOVECTOR_REST_BITS) - 1);
eassert (lisplen <= (1 << PSEUDOVECTOR_SIZE_BITS) - 1);
- /* Only the first lisplen slots will be traced normally by the GC. */
- for (i = 0; i < lisplen; ++i)
- v->contents[i] = Qnil;
+ /* Only the first lisplen slots will be traced normally by the GC.
+ But since Qnil == 0, we can memset Lisp_Object slots as well. */
+ memset (v->contents, 0, zerolen * word_size);
XSETPVECTYPESIZE (v, tag, lisplen, memlen - lisplen);
return v;
return b;
}
-struct Lisp_Hash_Table *
-allocate_hash_table (void)
-{
- return ALLOCATE_PSEUDOVECTOR (struct Lisp_Hash_Table, count, PVEC_HASH_TABLE);
-}
-
-struct window *
-allocate_window (void)
-{
- struct window *w;
-
- w = ALLOCATE_PSEUDOVECTOR (struct window, current_matrix, PVEC_WINDOW);
- /* Users assumes that non-Lisp data is zeroed. */
- memset (&w->current_matrix, 0,
- sizeof (*w) - offsetof (struct window, current_matrix));
- return w;
-}
-
-struct terminal *
-allocate_terminal (void)
-{
- struct terminal *t;
-
- t = ALLOCATE_PSEUDOVECTOR (struct terminal, next_terminal, PVEC_TERMINAL);
- /* Users assumes that non-Lisp data is zeroed. */
- memset (&t->next_terminal, 0,
- sizeof (*t) - offsetof (struct terminal, next_terminal));
- return t;
-}
-
-struct frame *
-allocate_frame (void)
-{
- struct frame *f;
-
- f = ALLOCATE_PSEUDOVECTOR (struct frame, face_cache, PVEC_FRAME);
- /* Users assumes that non-Lisp data is zeroed. */
- memset (&f->face_cache, 0,
- sizeof (*f) - offsetof (struct frame, face_cache));
- return f;
-}
-
-struct Lisp_Process *
-allocate_process (void)
-{
- struct Lisp_Process *p;
-
- p = ALLOCATE_PSEUDOVECTOR (struct Lisp_Process, pid, PVEC_PROCESS);
- /* Users assumes that non-Lisp data is zeroed. */
- memset (&p->pid, 0,
- sizeof (*p) - offsetof (struct Lisp_Process, pid));
- return p;
-}
-
DEFUN ("make-vector", Fmake_vector, Smake_vector, 2, 2, 0,
doc: /* Return a newly created vector of length LENGTH, with each element being INIT.
See also the function `vector'. */)
return hashfn_eq (ht, hash);
}
+/* Allocate basically initialized hash table. */
+
+static struct Lisp_Hash_Table *
+allocate_hash_table (void)
+{
+ return ALLOCATE_PSEUDOVECTOR (struct Lisp_Hash_Table,
+ count, PVEC_HASH_TABLE);
+}
+
/* An upper bound on the size of a hash table index. It must fit in
ptrdiff_t and be a valid Emacs fixnum. */
#define INDEX_SIZE_BOUND \
struct font_spec *spec
= ((struct font_spec *)
allocate_pseudovector (VECSIZE (struct font_spec),
- FONT_SPEC_MAX, PVEC_FONT));
+ FONT_SPEC_MAX, FONT_SPEC_MAX, PVEC_FONT));
XSETFONT (font_spec, spec);
return font_spec;
}
struct font_entity *entity
= ((struct font_entity *)
allocate_pseudovector (VECSIZE (struct font_entity),
- FONT_ENTITY_MAX, PVEC_FONT));
+ FONT_ENTITY_MAX, FONT_ENTITY_MAX, PVEC_FONT));
XSETFONT (font_entity, entity);
return font_entity;
}
{
Lisp_Object font_object;
struct font *font
- = (struct font *) allocate_pseudovector (size, FONT_OBJECT_MAX, PVEC_FONT);
+ = (struct font *) allocate_pseudovector (size, FONT_OBJECT_MAX,
+ FONT_OBJECT_MAX, PVEC_FONT);
int i;
/* GC can happen before the driver is set up,
run_window_configuration_change_hook (f);
}
+/* Allocate basically initialized frame. */
+
+static struct frame *
+allocate_frame (void)
+{
+ return ALLOCATE_ZEROED_PSEUDOVECTOR (struct frame, face_cache, PVEC_FRAME);
+}
struct frame *
make_frame (bool mini_p)
return v;
}
-extern struct Lisp_Vector *allocate_pseudovector (int, int, enum pvec_type);
-#define ALLOCATE_PSEUDOVECTOR(typ,field,tag) \
- ((typ*) \
- allocate_pseudovector \
- (VECSIZE (typ), PSEUDOVECSIZE (typ, field), tag))
-extern struct Lisp_Hash_Table *allocate_hash_table (void);
-extern struct window *allocate_window (void);
-extern struct frame *allocate_frame (void);
-extern struct Lisp_Process *allocate_process (void);
-extern struct terminal *allocate_terminal (void);
+extern struct Lisp_Vector *allocate_pseudovector (int, int, int,
+ enum pvec_type);
+
+/* Allocate partially initialized pseudovector where all Lisp_Object
+ slots are set to Qnil but the rest (if any) is left uninitialized. */
+
+#define ALLOCATE_PSEUDOVECTOR(type, field, tag) \
+ ((type *) allocate_pseudovector (VECSIZE (type), \
+ PSEUDOVECSIZE (type, field), \
+ PSEUDOVECSIZE (type, field), tag))
+
+/* Allocate fully initialized pseudovector where all Lisp_Object
+ slots are set to Qnil and the rest (if any) is zeroed. */
+
+#define ALLOCATE_ZEROED_PSEUDOVECTOR(type, field, tag) \
+ ((type *) allocate_pseudovector (VECSIZE (type), \
+ PSEUDOVECSIZE (type, field), \
+ VECSIZE (type), tag))
+
extern bool gc_in_progress;
extern bool abort_on_gc;
extern Lisp_Object make_float (double);
#endif /* HAVE_PTYS */
return -1;
}
-\f
+
+/* Allocate basically initialized process. */
+
+static struct Lisp_Process *
+allocate_process (void)
+{
+ return ALLOCATE_ZEROED_PSEUDOVECTOR (struct Lisp_Process, pid, PVEC_PROCESS);
+}
+
static Lisp_Object
make_process (Lisp_Object name)
{
return NULL;
}
+/* Allocate basically initialized terminal. */
+
+static struct terminal *
+allocate_terminal (void)
+{
+ return ALLOCATE_ZEROED_PSEUDOVECTOR
+ (struct terminal, next_terminal, PVEC_TERMINAL);
+}
+
/* Create a new terminal object of TYPE and add it to the terminal list. RIF
may be NULL if this terminal type doesn't support window-based redisplay. */
}
}
}
-\f
+
+/* Allocate basically initialized window. */
+
+static struct window *
+allocate_window (void)
+{
+ return ALLOCATE_ZEROED_PSEUDOVECTOR
+ (struct window, current_matrix, PVEC_WINDOW);
+}
+
/* Make new window, have it replace WINDOW in window-tree, and make
WINDOW its only vertical child (HORFLAG 1 means make WINDOW its only
horizontal child). */