Update array (extra) foreach implementation
This commit is contained in:
+8
-3
@@ -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;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user