[ruby/prism] Fix up pm_node_list_grow
https://github.com/ruby/prism/commit/7784365d3f
This commit is contained in:
parent
a33f19f783
commit
a64f1ab688
12
prism/node.h
12
prism/node.h
@ -17,18 +17,6 @@
|
|||||||
#define PM_NODE_LIST_FOREACH(list, index, node) \
|
#define PM_NODE_LIST_FOREACH(list, index, node) \
|
||||||
for (size_t index = 0; index < (list)->size && ((node) = (list)->nodes[index]); index++)
|
for (size_t index = 0; index < (list)->size && ((node) = (list)->nodes[index]); index++)
|
||||||
|
|
||||||
/**
|
|
||||||
* Attempts to grow the node list to the next size. If there is already
|
|
||||||
* capacity in the list, this function does nothing. Otherwise it reallocates
|
|
||||||
* the list to be twice as large as it was before. If the reallocation fails,
|
|
||||||
* this function returns false, otherwise it returns true.
|
|
||||||
*
|
|
||||||
* @param list The list to grow.
|
|
||||||
* @param size The number of nodes to grow the list by.
|
|
||||||
* @return True if the list was successfully grown, false otherwise.
|
|
||||||
*/
|
|
||||||
bool pm_node_list_grow(pm_node_list_t *list, size_t size);
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Append a new node onto the end of the node list.
|
* Append a new node onto the end of the node list.
|
||||||
*
|
*
|
||||||
|
@ -20,7 +20,7 @@ pm_node_list_memsize(pm_node_list_t *node_list, pm_memsize_t *memsize) {
|
|||||||
* the list to be twice as large as it was before. If the reallocation fails,
|
* the list to be twice as large as it was before. If the reallocation fails,
|
||||||
* this function returns false, otherwise it returns true.
|
* this function returns false, otherwise it returns true.
|
||||||
*/
|
*/
|
||||||
bool
|
static bool
|
||||||
pm_node_list_grow(pm_node_list_t *list, size_t size) {
|
pm_node_list_grow(pm_node_list_t *list, size_t size) {
|
||||||
size_t requested_size = list->size + size;
|
size_t requested_size = list->size + size;
|
||||||
|
|
||||||
@ -45,8 +45,12 @@ pm_node_list_grow(pm_node_list_t *list, size_t size) {
|
|||||||
next_capacity = double_capacity;
|
next_capacity = double_capacity;
|
||||||
}
|
}
|
||||||
|
|
||||||
list->nodes = (pm_node_t **) xrealloc(list->nodes, sizeof(pm_node_t *) * next_capacity);
|
pm_node_t **nodes = (pm_node_t **) xrealloc(list->nodes, sizeof(pm_node_t *) * next_capacity);
|
||||||
return list->nodes != NULL;
|
if (nodes == NULL) return false;
|
||||||
|
|
||||||
|
list->nodes = nodes;
|
||||||
|
list->capacity = next_capacity;
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
Loading…
x
Reference in New Issue
Block a user