Skip to content

Commit

Permalink
runtime: no need to protect key/value increments against end of bucket
Browse files Browse the repository at this point in the history
After the key and value arrays, we have an overflow pointer.
So there's no way a past-the-end key or value pointer could point
past the end of the containing bucket.

So we don't need this additional protection.

Update #21459

Change-Id: I7726140033b06b187f7a7d566b3af8cdcaeab0b0
Reviewed-on: https://go-review.googlesource.com/56772
Run-TryBot: Keith Randall <khr@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Martin Möhrmann <moehrmann@google.com>
Reviewed-by: Josh Bleecher Snyder <josharian@gmail.com>
Reviewed-by: Avelino <t@avelino.xxx>
  • Loading branch information
randall77 committed Aug 18, 2017
1 parent a937534 commit 77871cc
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions src/runtime/hashmap.go
Expand Up @@ -1119,12 +1119,12 @@ func evacuate(t *maptype, h *hmap, oldbucket uintptr) {
typedmemmove(t.elem, dst.v, v)
}
dst.i++
// If we're at the end of the bucket, don't update k/v,
// to avoid pointers pointing past the end of the bucket.
if dst.i < bucketCnt {
dst.k = add(dst.k, uintptr(t.keysize))
dst.v = add(dst.v, uintptr(t.valuesize))
}
// These updates might push these pointers past the end of the
// key or value arrays. That's ok, as we have the overflow pointer
// at the end of the bucket to protect against pointing past the
// end of the bucket.
dst.k = add(dst.k, uintptr(t.keysize))
dst.v = add(dst.v, uintptr(t.valuesize))
}
}
// Unlink the overflow buckets & clear key/value to help GC.
Expand Down

0 comments on commit 77871cc

Please sign in to comment.