diff options
Diffstat (limited to 'lib/hmap.c')
-rw-r--r-- | lib/hmap.c | 16 |
1 files changed, 11 insertions, 5 deletions
diff --git a/lib/hmap.c b/lib/hmap.c index d66cf271a..71943a74e 100644 --- a/lib/hmap.c +++ b/lib/hmap.c @@ -48,11 +48,17 @@ hmap_swap(struct hmap *a, struct hmap *b) struct hmap tmp = *a; *a = *b; *b = tmp; - if (a->buckets == &b->one) { - a->buckets = &a->one; - } - if (b->buckets == &a->one) { - b->buckets = &b->one; + hmap_moved(a); + hmap_moved(b); +} + +/* Adjusts 'hmap' to compensate for having moved position in memory (e.g. due + * to realloc()). */ +void +hmap_moved(struct hmap *hmap) +{ + if (!hmap->mask) { + hmap->buckets = &hmap->one; } } |