Ruby: prism/util/pm_string_list.c Source File

Ruby 3.3.6p108 (2024-11-05 revision 75015d4c1f6965b5e85e96fb309f1f2129f933c0)

pm_string_list.c
1#include "prism/util/pm_string_list.h"
2
6void
7pm_string_list_append(pm_string_list_t *string_list, pm_string_t *string) {
8 if (string_list->length + 1 > string_list->capacity) {
9 if (string_list->capacity == 0) {
10 string_list->capacity = 1;
11 } else {
12 string_list->capacity *= 2;
13 }
14
15 string_list->strings = realloc(string_list->strings, string_list->capacity * sizeof(pm_string_t));
16 if (string_list->strings == NULL) abort();
17 }
18
19 string_list->strings[string_list->length++] = *string;
20}
21
25void
26pm_string_list_free(pm_string_list_t *string_list) {
27 free(string_list->strings);
28}
pm_string_list.h
A list of strings.
pm_string_list_t
A list of strings.
Definition pm_string_list.h:18
pm_string_list_t::capacity
size_t capacity
The capacity of the string list that has been allocated.
Definition pm_string_list.h:23
pm_string_list_t::strings
pm_string_t * strings
A pointer to the start of the string list.
Definition pm_string_list.h:26
pm_string_list_t::length
size_t length
The length of the string list.
Definition pm_string_list.h:20
pm_string_t
A generic string type that can have various ownership semantics.
Definition pm_string.h:30