Mercurial > libedl
comparison src/edl.c @ 6:7137fbac0b85
edl: expose EDL_reallocate() API to allow resizing the array
author | Paper <mrpapersonic@gmail.com> |
---|---|
date | Thu, 28 Dec 2023 16:47:24 -0500 |
parents | c2408abb258a |
children | 0c98b46eaf73 |
comparison
equal
deleted
inserted
replaced
5:a6ab6d9c0dac | 6:7137fbac0b85 |
---|---|
142 return EDL_internal_append_offset(input, offset, length); | 142 return EDL_internal_append_offset(input, offset, length); |
143 } | 143 } |
144 | 144 |
145 /* memory management routines */ | 145 /* memory management routines */ |
146 | 146 |
147 static int EDL_internal_reallocate(EDL* input, size_t new_capacity) { | 147 int EDL_reallocate(EDL* input, size_t new_capacity) { |
148 input->arr = realloc(input->arr, new_capacity * sizeof(EDL_line)); | 148 input->arr = realloc(input->arr, new_capacity * sizeof(EDL_line)); |
149 if (!input->arr) | 149 if (!input->arr) |
150 return 0; | 150 return 0; |
151 | 151 |
152 if (new_capacity > input->capacity) | 152 if (new_capacity > input->capacity) |
158 } | 158 } |
159 | 159 |
160 /* the important function */ | 160 /* the important function */ |
161 EDL EDL_parse(const char* data, size_t length) { | 161 EDL EDL_parse(const char* data, size_t length) { |
162 EDL edl = {0}; | 162 EDL edl = {0}; |
163 if (!EDL_internal_reallocate(&edl, 16)) | 163 if (!EDL_reallocate(&edl, 16)) |
164 return edl; | 164 return edl; |
165 | 165 |
166 size_t order_size = 0; | 166 size_t order_size = 0; |
167 uint32_t* order = EDL_internal_parse_first_line(data, &order_size); | 167 uint32_t* order = EDL_internal_parse_first_line(data, &order_size); |
168 | 168 |
280 | 280 |
281 if (!ok) | 281 if (!ok) |
282 break; | 282 break; |
283 | 283 |
284 if (++edl.size >= edl.capacity) | 284 if (++edl.size >= edl.capacity) |
285 EDL_internal_reallocate(&edl, edl.capacity * 2); | 285 EDL_reallocate(&edl, edl.capacity * 2); |
286 } | 286 } |
287 | 287 |
288 EDL_internal_reallocate(&edl, edl.size); | 288 EDL_reallocate(&edl, edl.size); |
289 | 289 |
290 free(order); | 290 free(order); |
291 | 291 |
292 return edl; | 292 return edl; |
293 } | 293 } |