From 7b7d65008c51c8d20cc770ddaa53b2b6f1e0c9a6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=B6nke=20Ludwig?= Date: Fri, 13 Dec 2024 14:31:40 +0100 Subject: [PATCH] Fix missing copy/postblit constructor call when resizing non-unique hash maps. --- source/vibe/container/hashmap.d | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/source/vibe/container/hashmap.d b/source/vibe/container/hashmap.d index b44181d..265d5c5 100644 --- a/source/vibe/container/hashmap.d +++ b/source/vibe/container/hashmap.d @@ -300,16 +300,24 @@ struct HashMap(TKey, TValue, Traits = DefaultHashMapTraits!TKey, Allocator = IAl // allocate the new array, automatically initializes with empty entries (Traits.clearValue) m_table = m_table.createNew(new_size); + if (oldtable.isUnique) { // perform a move operation of all non-empty elements from the old array to the new one - foreach (ref el; oldtable) + foreach (ref el; oldtable) if (!Traits.equals(el.key, Traits.clearValue)) { - auto idx = findInsertIndex(el.key); - (cast(ubyte[])(&m_table[idx])[0 .. 1])[] = (cast(ubyte[])(&el)[0 .. 1])[]; - } + auto idx = findInsertIndex(el.key); + (cast(ubyte[])(&m_table[idx])[0 .. 1])[] = (cast(ubyte[])(&el)[0 .. 1])[]; + } - // free the old table without calling destructors - if (oldtable.isUnique) + // free the old table without calling destructors oldtable.deallocate(); + } else { + // perform a copy operation of all non-empty elements from the old array to the new one + foreach (ref el; oldtable) + if (!Traits.equals(el.key, Traits.clearValue)) { + auto idx = findInsertIndex(el.key); + m_table[idx] = el; + } + } } }