Lines Matching refs:buf
47 util_dynarray_init(struct util_dynarray *buf) in util_dynarray_init() argument
49 memset(buf, 0, sizeof(*buf)); in util_dynarray_init()
53 util_dynarray_fini(struct util_dynarray *buf) in util_dynarray_fini() argument
55 if(buf->data) in util_dynarray_fini()
57 FREE(buf->data); in util_dynarray_fini()
58 util_dynarray_init(buf); in util_dynarray_fini()
64 util_dynarray_resize(struct util_dynarray *buf, unsigned newsize) in util_dynarray_resize() argument
67 if(newsize > buf->capacity) in util_dynarray_resize()
69 unsigned newcap = buf->capacity << 1; in util_dynarray_resize()
72 buf->data = REALLOC(buf->data, buf->capacity, newcap); in util_dynarray_resize()
73 buf->capacity = newcap; in util_dynarray_resize()
76 p = (char *)buf->data + buf->size; in util_dynarray_resize()
77 buf->size = newsize; in util_dynarray_resize()
82 util_dynarray_grow(struct util_dynarray *buf, int diff) in util_dynarray_grow() argument
84 return util_dynarray_resize(buf, buf->size + diff); in util_dynarray_grow()
88 util_dynarray_trim(struct util_dynarray *buf) in util_dynarray_trim() argument
90 if (buf->size != buf->capacity) { in util_dynarray_trim()
91 if (buf->size) { in util_dynarray_trim()
92 buf->data = REALLOC(buf->data, buf->capacity, buf->size); in util_dynarray_trim()
93 buf->capacity = buf->size; in util_dynarray_trim()
96 FREE(buf->data); in util_dynarray_trim()
97 buf->data = 0; in util_dynarray_trim()
98 buf->capacity = 0; in util_dynarray_trim()
103 #define util_dynarray_append(buf, type, v) do {type __v = (v); memcpy(util_dynarray_grow((buf), siz… argument
104 #define util_dynarray_top_ptr(buf, type) (type*)((char*)(buf)->data + (buf)->size - sizeof(type)) argument
105 #define util_dynarray_top(buf, type) *util_dynarray_top_ptr(buf, type) argument
106 #define util_dynarray_pop_ptr(buf, type) (type*)((char*)(buf)->data + ((buf)->size -= sizeof(type))) argument
107 #define util_dynarray_pop(buf, type) *util_dynarray_pop_ptr(buf, type) argument
108 #define util_dynarray_contains(buf, type) ((buf)->size >= sizeof(type)) argument
109 #define util_dynarray_element(buf, type, idx) ((type*)(buf)->data + (idx)) argument
110 #define util_dynarray_begin(buf) ((buf)->data) argument
111 #define util_dynarray_end(buf) ((void*)util_dynarray_element((buf), char, (buf)->size)) argument