diff --git a/vlib/builtin/map.v b/vlib/builtin/map.v index 47dbba29ba..c92ab3b1b3 100644 --- a/vlib/builtin/map.v +++ b/vlib/builtin/map.v @@ -175,14 +175,16 @@ fn (mut d DenseArray) zeros_to_end() { if d.has_index(i) { // swap (TODO: optimize) unsafe { - // Swap keys - C.memcpy(tmp_key, d.key(count), d.key_bytes) - C.memcpy(d.key(count), d.key(i), d.key_bytes) - C.memcpy(d.key(i), tmp_key, d.key_bytes) - // Swap values - C.memcpy(tmp_value, d.value(count), d.value_bytes) - C.memcpy(d.value(count), d.value(i), d.value_bytes) - C.memcpy(d.value(i), tmp_value, d.value_bytes) + if count != i { + // Swap keys + C.memcpy(tmp_key, d.key(count), d.key_bytes) + C.memcpy(d.key(count), d.key(i), d.key_bytes) + C.memcpy(d.key(i), tmp_key, d.key_bytes) + // Swap values + C.memcpy(tmp_value, d.value(count), d.value_bytes) + C.memcpy(d.value(count), d.value(i), d.value_bytes) + C.memcpy(d.value(i), tmp_value, d.value_bytes) + } } count++ }