improve _add_PtkList performance

This commit is contained in:
jacekpoz 2024-08-23 08:43:51 +02:00
parent e2e486a215
commit 04ff88c4e6
Signed by: poz
SSH key fingerprint: SHA256:JyLeVWE4bF3tDnFeUpUaJsPsNlJyBldDGV/dIKSLyN8

View file

@ -22,24 +22,17 @@ bool _grow_PtkList(void **data, uint32_t *allocated, size_t element_size) {
}
bool _add_PtkList(void **data, uint32_t *size, uint32_t *allocated, void *elements, size_t element_count, size_t element_size) {
size_t elements_added = 0;
for (size_t i = 0; i < element_count; ++i) {
if (*size == *allocated) {
while (*allocated < *size + element_count) {
if (!_grow_PtkList(data, allocated, element_size)) {
break;
return false;
}
}
uint8_t *element = ((uint8_t *)elements) + (i * element_size);
uint8_t *target = ((uint8_t *)*data) + (*size * element_size);
memcpy(target, element, element_size);
elements_added += 1;
*size += 1;
}
memcpy(target, (uint8_t *)elements, element_size * element_count);
*size += element_count;
return elements_added == element_count;
return true;
}
bool _remove_PtkList(void *data, uint32_t *size, void *elements, size_t element_count, size_t element_size) {