#endif /* MAX_SAVE_STACK > 0 */
+static struct Lisp_Vector *allocate_clear_vector (ptrdiff_t, bool);
static void unchain_finalizer (struct Lisp_Finalizer *);
static void mark_terminals (void);
static void gc_sweep (void);
return a;
}
-/* Return a newly allocated, uninitialized bool vector of size NBITS. */
+/* Return a newly allocated, bool vector of size NBITS. If CLEARIT,
+ clear its slots; otherwise the vector's slots are uninitialized. */
Lisp_Object
-make_uninit_bool_vector (EMACS_INT nbits)
+make_clear_bool_vector (EMACS_INT nbits, bool clearit)
{
Lisp_Object val;
EMACS_INT words = bool_vector_words (nbits);
if (PTRDIFF_MAX < needed_elements)
memory_full (SIZE_MAX);
struct Lisp_Bool_Vector *p
- = (struct Lisp_Bool_Vector *) allocate_vector (needed_elements);
+ = (struct Lisp_Bool_Vector *) allocate_clear_vector (needed_elements,
+ clearit);
+ /* Clear padding at end; but only if necessary, to avoid polluting the
+ data cache. */
+ if (!clearit && nbits % BITS_PER_BITS_WORD != 0)
+ p->data[words - 1] = 0;
+
XSETVECTOR (val, p);
XSETPVECTYPESIZE (XVECTOR (val), PVEC_BOOL_VECTOR, 0, 0);
p->size = nbits;
+ return val;
+}
- /* Clear padding at the end. */
- if (words)
- p->data[words - 1] = 0;
+/* Return a newly allocated, uninitialized bool vector of size NBITS. */
- return val;
+Lisp_Object
+make_uninit_bool_vector (EMACS_INT nbits)
+{
+ return make_clear_bool_vector (nbits, false);
}
DEFUN ("make-bool-vector", Fmake_bool_vector, Smake_bool_vector, 2, 2, 0,
LENGTH must be a number. INIT matters only in whether it is t or nil. */)
(Lisp_Object length, Lisp_Object init)
{
- Lisp_Object val;
-
CHECK_FIXNAT (length);
- val = make_uninit_bool_vector (XFIXNAT (length));
- return bool_vector_fill (val, init);
+ Lisp_Object val = make_clear_bool_vector (XFIXNAT (length), NILP (init));
+ return NILP (init) ? val : bool_vector_fill (val, init);
}
DEFUN ("bool-vector", Fbool_vector, Sbool_vector, 0, MANY, 0,
usage: (bool-vector &rest OBJECTS) */)
(ptrdiff_t nargs, Lisp_Object *args)
{
- ptrdiff_t i;
- Lisp_Object vector;
-
- vector = make_uninit_bool_vector (nargs);
- for (i = 0; i < nargs; i++)
- bool_vector_set (vector, i, !NILP (args[i]));
-
+ Lisp_Object vector = make_clear_bool_vector (nargs, true);
+ for (ptrdiff_t i = 0; i < nargs; i++)
+ if (!NILP (args[i]))
+ bool_vector_set (vector, i, true);
return vector;
}
}
else if (BOOL_VECTOR_P (seq))
{
- ptrdiff_t i;
EMACS_INT nbits = bool_vector_size (seq);
- new = make_uninit_bool_vector (nbits);
- for (i = 0; i < nbits; i++)
- bool_vector_set (new, i, bool_vector_bitref (seq, nbits - i - 1));
+ new = make_clear_bool_vector (nbits, true);
+ for (ptrdiff_t i = 0; i < nbits; i++)
+ if (bool_vector_bitref (seq, nbits - i - 1))
+ bool_vector_set (new, i, true);
}
else if (STRINGP (seq))
{