From cd8ad4c1f64a4f7d79d8517c90e3d518d679ea14 Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Tue, 17 Dec 2024 07:37:34 +0530 Subject: [PATCH] Always zero memory from arena --- kitty/arena.h | 7 ++----- kitty/glyph-cache.c | 1 - kitty/text-cache.c | 3 ++- 3 files changed, 4 insertions(+), 7 deletions(-) diff --git a/kitty/arena.h b/kitty/arena.h index f69b0e9eac..719bd52f74 100644 --- a/kitty/arena.h +++ b/kitty/arena.h @@ -51,11 +51,9 @@ MA_CAT(MA_NAME, _get)(MA_TYPE_NAME *self, size_t sz) { void *chunk = NULL; if (MA_BLOCK_SIZE >= sizeof(void*) && MA_BLOCK_SIZE % sizeof(void*) == 0) { if (posix_memalign(&chunk, MA_BLOCK_SIZE, block_sz) != 0) chunk = NULL; - } else chunk = malloc(block_sz); + memset(chunk, 0, block_sz); + } else chunk = calloc(1, block_sz); if (!chunk) { return NULL; } -#ifdef MA_ZERO_MEMORY - memset(chunk, 0, block_sz); -#endif if (count > self->capacity) { size_t capacity = MAX(8u, 2 * self->capacity); MA_BLOCK_TYPE_NAME *blocks = realloc(self->blocks, capacity * sizeof(MA_BLOCK_TYPE_NAME)); @@ -75,6 +73,5 @@ MA_CAT(MA_NAME, _get)(MA_TYPE_NAME *self, size_t sz) { #undef MA_ARENA_NUM_BLOCKS #undef MA_TYPE_NAME #undef MA_BLOCK_TYPE_NAME -#undef MA_ZERO_MEMORY #undef MA_CAT #undef MA_CAT_ diff --git a/kitty/glyph-cache.c b/kitty/glyph-cache.c index c95301312e..66fc13567c 100644 --- a/kitty/glyph-cache.c +++ b/kitty/glyph-cache.c @@ -28,7 +28,6 @@ static_assert(MA_BLOCK_SIZE > sizeof(SpritePosKey) + 2, "increase arena block si #define MA_NAME Val #define MA_BLOCK_SIZE sizeof(VAL_TY) #define MA_ARENA_NUM_BLOCKS (2048u / MA_BLOCK_SIZE) -#define MA_ZERO_MEMORY #include "arena.h" diff --git a/kitty/text-cache.c b/kitty/text-cache.c index 807d907006..8e8ebe7551 100644 --- a/kitty/text-cache.c +++ b/kitty/text-cache.c @@ -7,9 +7,10 @@ #include "data-types.h" typedef struct Chars { - size_t count; const char_type *chars; + size_t count; } Chars; +static_assert(sizeof(Chars) == sizeof(void*) + sizeof(size_t), "reorder Chars"); #define NAME chars_map #define KEY_TY Chars