1
0
mirror of https://github.com/vlang/v.git synced 2023-08-10 21:13:21 +03:00

builtin: fix map.zeros_to_end ()

This commit is contained in:
ka-weihe 2021-04-11 23:36:02 +02:00 committed by GitHub
parent 79fa15ec3a
commit 0facc5a559
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -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++
}