diff options
author | Vicențiu Ciorbaru <cvicentiu@gmail.com> | 2013-10-17 15:03:04 -0700 |
---|---|---|
committer | Sergei Golubchik <sergii@pisem.net> | 2013-10-17 15:03:04 -0700 |
commit | 89229fb71c5c0db7958915b9ed10a6d0f7f4b0a3 (patch) | |
tree | 37b3c9aaf766d2975dfe56a7fa4781859efe1ce7 /mysys/array.c | |
parent | 9e7228dc4ae7cc9eee1df93eb0aeec540ca20c80 (diff) | |
download | mariadb-git-89229fb71c5c0db7958915b9ed10a6d0f7f4b0a3.tar.gz |
Added a delete_function for DYNAMIC_ARRAY.
The function calls delete_dynamic, after if calls a free function on every
array element.
Diffstat (limited to 'mysys/array.c')
-rw-r--r-- | mysys/array.c | 17 |
1 files changed, 17 insertions, 0 deletions
diff --git a/mysys/array.c b/mysys/array.c index f72b8951870..fe75f2a536c 100644 --- a/mysys/array.c +++ b/mysys/array.c @@ -321,7 +321,24 @@ void delete_dynamic_element(DYNAMIC_ARRAY *array, uint idx) (array->elements-idx)*array->size_of_element); } +/* + Wrapper around delete_dynamic, calling a FREE function on every + element, before releasing the memory + SYNOPSIS + delete_dynamic_recursive() + array + f The function to be called on every element before + deleting the array; +*/ +void delete_dynamic_recursive(DYNAMIC_ARRAY *array, FREE_FUNC f) { + uint i; + char *ptr= (char*) array->buffer; + for (i= 0; i < array->elements; i++, ptr+= array->size_of_element) { + f(ptr); + } + delete_dynamic(array); +} /* Free unused memory |