diff options
author | Bruno Haible <bruno@clisp.org> | 2018-12-12 01:14:34 +0100 |
---|---|---|
committer | Bruno Haible <bruno@clisp.org> | 2018-12-12 01:14:34 +0100 |
commit | 1a833ed0ddb6e482b121f813e00e5e2b5e79a8d2 (patch) | |
tree | b08913e3855e53ea226949806e0335dc9ff957a6 /lib/gl_array_omap.c | |
parent | 821015b5747ecf99422ada31398bde8dd7549970 (diff) | |
download | gnulib-1a833ed0ddb6e482b121f813e00e5e2b5e79a8d2.tar.gz |
omap: Don't dispose the old value when the function returns it.
* lib/gl_array_omap.c (gl_array_remove_at): Don't invoke the vdispose_fn
here.
* lib/gl_avltree_omap.c (NODE_PAYLOAD_DISPOSE): Likewise.
* lib/gl_rbtree_omap.c (NODE_PAYLOAD_DISPOSE): Likewise.
* lib/gl_omap.h (gl_omap_nx_put, gl_omap_remove): Invoke the vdispose_fn
here.
Diffstat (limited to 'lib/gl_array_omap.c')
-rw-r--r-- | lib/gl_array_omap.c | 36 |
1 files changed, 17 insertions, 19 deletions
diff --git a/lib/gl_array_omap.c b/lib/gl_array_omap.c index a2b21bc3ad..3b65269c0e 100644 --- a/lib/gl_array_omap.c +++ b/lib/gl_array_omap.c @@ -220,25 +220,6 @@ gl_array_nx_add_at (gl_omap_t map, size_t position, return 1; } -/* Remove the pair at the given position, - 0 <= position < gl_omap_size (map). */ -static void -gl_array_remove_at (gl_omap_t map, size_t position) -{ - size_t count = map->count; - struct pair *pairs; - size_t i; - - pairs = map->pairs; - if (map->base.vdispose_fn != NULL) - map->base.vdispose_fn (pairs[position].value); - if (map->base.kdispose_fn != NULL) - map->base.kdispose_fn (pairs[position].key); - for (i = position + 1; i < count; i++) - pairs[i - 1] = pairs[i]; - map->count = count - 1; -} - static int gl_array_nx_getput (gl_omap_t map, const void *key, const void *value, const void **oldvaluep) @@ -279,6 +260,23 @@ gl_array_nx_getput (gl_omap_t map, const void *key, const void *value, return gl_array_nx_add_at (map, low, key, value); } +/* Remove the pair at the given position, + 0 <= position < gl_omap_size (map). */ +static void +gl_array_remove_at (gl_omap_t map, size_t position) +{ + size_t count = map->count; + struct pair *pairs; + size_t i; + + pairs = map->pairs; + if (map->base.kdispose_fn != NULL) + map->base.kdispose_fn (pairs[position].key); + for (i = position + 1; i < count; i++) + pairs[i - 1] = pairs[i]; + map->count = count - 1; +} + static bool gl_array_getremove (gl_omap_t map, const void *key, const void **oldvaluep) { |