Improve ARRAY
This commit is contained in:
parent
b4cc98e63c
commit
c43e9f348f
21
hex.c
21
hex.c
|
@ -103,23 +103,20 @@ update_curses_terminal_size (void)
|
||||||
|
|
||||||
// --- Simple array support ----------------------------------------------------
|
// --- Simple array support ----------------------------------------------------
|
||||||
|
|
||||||
// Primitives for arrays
|
// The most basic helper macros to make working with arrays not suck
|
||||||
|
|
||||||
#define ARRAY(type, name) type *name; size_t name ## _len, name ## _size;
|
#define ARRAY(type, name) type *name; size_t name ## _len, name ## _size;
|
||||||
#define ARRAY_INIT(a) \
|
#define ARRAY_INIT_SIZED(a, n) \
|
||||||
BLOCK_START \
|
BLOCK_START \
|
||||||
a = xcalloc (sizeof *a, (a ## _size = 16)); \
|
(a) = xcalloc (sizeof *(a), (a ## _size) = (n)); \
|
||||||
a ## _len = 0; \
|
(a ## _len) = 0; \
|
||||||
BLOCK_END
|
BLOCK_END
|
||||||
|
#define ARRAY_INIT(a) ARRAY_INIT_SIZED (a, 16)
|
||||||
#define ARRAY_RESERVE(a, n) \
|
#define ARRAY_RESERVE(a, n) \
|
||||||
array_reserve ((void **) &a, sizeof *a, a ## _len + n, &a ## _size)
|
BLOCK_START \
|
||||||
|
while ((a ## _size) - (a ## _len) < n) \
|
||||||
static void
|
(a) = xreallocarray ((a), sizeof *(a), (a ## _size) <<= 1); \
|
||||||
array_reserve (void **array, size_t element_size, size_t len, size_t *size)
|
BLOCK_END
|
||||||
{
|
|
||||||
while (len > *size)
|
|
||||||
*array = xreallocarray (*array, element_size, *size <<= 1);
|
|
||||||
}
|
|
||||||
|
|
||||||
// --- Application -------------------------------------------------------------
|
// --- Application -------------------------------------------------------------
|
||||||
|
|
||||||
|
|
1
tui.c
1
tui.c
|
@ -90,6 +90,7 @@ struct row_char
|
||||||
|
|
||||||
struct row_buffer
|
struct row_buffer
|
||||||
{
|
{
|
||||||
|
// TODO: rewrite this using ARRAY
|
||||||
struct row_char *chars; ///< Characters
|
struct row_char *chars; ///< Characters
|
||||||
size_t chars_len; ///< Character count
|
size_t chars_len; ///< Character count
|
||||||
size_t chars_alloc; ///< Characters allocated
|
size_t chars_alloc; ///< Characters allocated
|
||||||
|
|
Loading…
Reference in New Issue