Skip to content

Commit

Permalink
Always zero memory from arena
Browse files Browse the repository at this point in the history
  • Loading branch information
kovidgoyal committed Dec 18, 2024
1 parent 4b39d50 commit cd8ad4c
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 7 deletions.
7 changes: 2 additions & 5 deletions kitty/arena.h
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand All @@ -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_
1 change: 0 additions & 1 deletion kitty/glyph-cache.c
Original file line number Diff line number Diff line change
Expand Up @@ -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"


Expand Down
3 changes: 2 additions & 1 deletion kitty/text-cache.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit cd8ad4c

Please sign in to comment.