summaryrefslogtreecommitdiff
path: root/lib/gl_array_omap.c
diff options
context:
space:
mode:
authorBruno Haible <bruno@clisp.org>2018-12-12 01:14:34 +0100
committerBruno Haible <bruno@clisp.org>2018-12-12 01:14:34 +0100
commit1a833ed0ddb6e482b121f813e00e5e2b5e79a8d2 (patch)
treeb08913e3855e53ea226949806e0335dc9ff957a6 /lib/gl_array_omap.c
parent821015b5747ecf99422ada31398bde8dd7549970 (diff)
downloadgnulib-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.c36
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)
{