diff options
author | Přemysl Janouch <p.janouch@gmail.com> | 2017-06-05 18:57:54 +0200 |
---|---|---|
committer | Přemysl Janouch <p.janouch@gmail.com> | 2017-06-05 18:59:23 +0200 |
commit | e62c41f4a1d7235e1ecafb7fb65eeb0cd8e8d795 (patch) | |
tree | b261207e4a8aab38d01f1733cf6e2d7b7b1a5c9d /nncmpp.c | |
parent | b050113eed6a19f22ae885c63e3d5140f9d1ec38 (diff) | |
download | nncmpp-e62c41f4a1d7235e1ecafb7fb65eeb0cd8e8d795.tar.gz nncmpp-e62c41f4a1d7235e1ecafb7fb65eeb0cd8e8d795.tar.xz nncmpp-e62c41f4a1d7235e1ecafb7fb65eeb0cd8e8d795.zip |
Use the ARRAY abstraction
Diffstat (limited to 'nncmpp.c')
-rw-r--r-- | nncmpp.c | 19 |
1 files changed, 6 insertions, 13 deletions
@@ -2675,8 +2675,7 @@ struct debug_item static struct { struct tab super; ///< Parent class - struct debug_item *items; ///< Items - size_t items_alloc; ///< How many items are allocated + ARRAY (struct debug_item, items) ///< Items bool active; ///< The tab is present } g_debug_tab; @@ -2684,7 +2683,7 @@ g_debug_tab; static void debug_tab_on_item_draw (size_t item_index, struct row_buffer *buffer, int width) { - hard_assert (item_index <= g_debug_tab.super.item_count); + hard_assert (item_index < g_debug_tab.items_len); struct debug_item *item = &g_debug_tab.items[item_index]; char buf[16]; @@ -2707,16 +2706,11 @@ debug_tab_on_item_draw (size_t item_index, struct row_buffer *buffer, int width) static void debug_tab_push (const char *message, chtype attrs) { - // TODO: uh... aren't we rather going to write our own abstraction? - if (g_debug_tab.items_alloc <= g_debug_tab.super.item_count) - { - g_debug_tab.items = xreallocarray (g_debug_tab.items, - sizeof *g_debug_tab.items, (g_debug_tab.items_alloc <<= 1)); - } + ARRAY_RESERVE (g_debug_tab.items, 1); // TODO: there should be a better, more efficient mechanism for this - struct debug_item *item = - &g_debug_tab.items[g_debug_tab.super.item_count++]; + struct debug_item *item = &g_debug_tab.items[g_debug_tab.items_len++]; + g_debug_tab.super.item_count = g_debug_tab.items_len; item->text = xstrdup (message); item->attrs = attrs; item->timestamp = clock_msec (CLOCK_REALTIME); @@ -2727,8 +2721,7 @@ debug_tab_push (const char *message, chtype attrs) static struct tab * debug_tab_init (void) { - g_debug_tab.items = xcalloc - ((g_debug_tab.items_alloc = 16), sizeof *g_debug_tab.items); + ARRAY_INIT (g_debug_tab.items); g_debug_tab.active = true; struct tab *super = &g_debug_tab.super; |