on master help sign in
Implement node reallocation
commitec36b50f06233047fd79a5321a0380cd3978f3b4 authorNeil Mitchell <ndmitchell@gmail.com> dateWed 30 Nov 2016, 19:08 (10 years ago) parentced46a4
1 file changed+8−1
cbits/hexml.c+8−1
cbits/hexml.c+8−1
@@ -290,7 +290,14 @@ void static inline node_alloc(node_buffer* b, int ask)
290290{
291291 int space = b->size - b->used_back - b->used_front;
292292 if (space >= ask) return;
293− assert(0);
293+ int size2 = (b->size + 1000 + ask) * 2;
294+ node* buf2 = malloc(size2 * sizeof(node));
295+ memcpy(buf2, b->nodes, b->used_front * sizeof(node));
296+ memcpy(&buf2[size2 - b->used_back], &b->nodes[b->size - b->used_back], b->used_back * sizeof(node));
297+ free(b->alloc);
298+ b->size = size2;
299+ b->nodes = buf2;
300+ b->alloc = buf2;
294301}
295302
296303void static inline attr_alloc(attr_buffer* b, int ask)