This commit is contained in:
Neil 2021-08-29 13:32:34 -07:00
parent d2bc0e161d
commit 47d7cb878a
1 changed files with 6 additions and 8 deletions

View File

@ -52,10 +52,9 @@ static int name##_array_reserve(struct name##_array *const a, \
a->data = data, a->capacity = c0; \ a->data = data, a->capacity = c0; \
return 1; \ return 1; \
} \ } \
/** The capacity of `a` will be increased to at least `n` elements beyond the /** Increases the capacity of `a` to at least `n` elements beyond the size.
size. It will invalidate pointers in `a` if `n` is greater than the buffer @return The start of the buffered space at the back of the array. If `a` is
space. @return The start of the buffered space at the back of the array. If idle and `buffer` is zero, a null pointer is returned, otherwise null
`a` is idle and `buffer` is zero, a null pointer is returned, otherwise null
indicates an error. @throws[realloc, ERANGE] */ \ indicates an error. @throws[realloc, ERANGE] */ \
static type *name##_array_buffer(struct name##_array *const a, \ static type *name##_array_buffer(struct name##_array *const a, \
const size_t n) { \ const size_t n) { \
@ -64,8 +63,7 @@ static type *name##_array_buffer(struct name##_array *const a, \
return name##_array_reserve(a, a->size + n) && a->data \ return name##_array_reserve(a, a->size + n) && a->data \
? a->data + a->size : 0; \ ? a->data + a->size : 0; \
} \ } \
/** Adds `n` elements to the back of `a`. It will invalidate pointers in `a` if /** Adds `n` elements to the back of `a`. @return A pointer to the elements. If
`n` is greater than the buffer space. @return A pointer to the elements. If
`a` is idle and `n` is zero, a null pointer will be returned, otherwise null `a` is idle and `n` is zero, a null pointer will be returned, otherwise null
indicates an error. @throws[realloc, ERANGE] */ \ indicates an error. @throws[realloc, ERANGE] */ \
static type *name##_array_append(struct name##_array *const a, \ static type *name##_array_append(struct name##_array *const a, \
@ -75,8 +73,8 @@ static type *name##_array_append(struct name##_array *const a, \
assert(n <= a->capacity && a->size <= a->capacity - n); \ assert(n <= a->capacity && a->size <= a->capacity - n); \
return a->size += n, buffer; \ return a->size += n, buffer; \
} \ } \
/** @return Adds (push back) one new element of `a`. The buffer holds an /** @return Adds (push back) one new element of `a`.
element or it will invalidate pointers in `a`. @throws[realloc, ERANGE] */ \ @throws[realloc, ERANGE] */ \
static type *name##_array_new(struct name##_array *const a) \ static type *name##_array_new(struct name##_array *const a) \
{ return name##_array_append(a, 1); } \ { return name##_array_append(a, 1); } \
/* It's perfectly valid that these functions are not used. */ \ /* It's perfectly valid that these functions are not used. */ \