Update array (extra) foreach implementation

This commit is contained in:
2022-06-08 09:57:41 +03:00
parent 624efada63
commit 472639a681
2 changed files with 13 additions and 5 deletions
+8 -3
View File
@@ -76,7 +76,7 @@ ssize_t libcdsb_array_get(val_t* x, arr_t* s, ssize_t i, _Bool cut) {
/*#####################################################################################################################*/
int libcdsb_array_foreach(const vtype_array* x, void* data, int (*callback)(void* value, ssize_t index, vtype type, void* data)) {
int libcdsb_array_foreach(vtype_array* x, void* data, array_foreach_callback callback, _Bool flush) {
void* p;
void* e;
@@ -86,14 +86,19 @@ int libcdsb_array_foreach(const vtype_array* x, void* data, int (*callback)(void
p = x->mem;
e = x->mem + x->size*vtype_size(x->type);
n = 0;
r = 0;
while (p < e) {
if ((r = callback(p, n, x->type, data)))
return r;
break;
p += vtype_size(x->type);
++n;
}
return 0;
if (flush) {
free(x->mem);
memset(x, 0, sizeof(*x));
}
return r;
}