diff options
| author | Austin Clements <austin@google.com> | 2018-09-25 17:24:30 -0400 |
|---|---|---|
| committer | Austin Clements <austin@google.com> | 2018-10-09 18:20:23 +0000 |
| commit | 416804f3e24b25cf3e291fbbe5857cc28644a852 (patch) | |
| tree | 702cc815d0b922363994687bf1f89afaab6e50c9 /src/runtime/mcentral.go | |
| parent | 70d7e96c7850d141ae48e99f02a397aed1bc474b (diff) | |
| download | go-416804f3e24b25cf3e291fbbe5857cc28644a852.tar.xz | |
runtime: simplify free count calculation in (un)cacheSpan
For unclear reasons, cacheSpan and uncacheSpan compute the number of
elements in a span by dividing its size by the element size. This
number is simply available in the mspan structure, so just use it.
Change-Id: If2e5de6ecec39befd3324bf1da4a275ad000932f
Reviewed-on: https://go-review.googlesource.com/c/138656
Run-TryBot: Austin Clements <austin@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
Diffstat (limited to 'src/runtime/mcentral.go')
| -rw-r--r-- | src/runtime/mcentral.go | 6 |
1 files changed, 2 insertions, 4 deletions
diff --git a/src/runtime/mcentral.go b/src/runtime/mcentral.go index d94b95792c..d9bc8b4719 100644 --- a/src/runtime/mcentral.go +++ b/src/runtime/mcentral.go @@ -117,8 +117,7 @@ havespan: if trace.enabled && !traceDone { traceGCSweepDone() } - cap := int32((s.npages << _PageShift) / s.elemsize) - n := cap - int32(s.allocCount) + n := int(s.nelems) - int(s.allocCount) if n == 0 || s.freeindex == s.nelems || uintptr(s.allocCount) == s.nelems { throw("span has no free objects") } @@ -168,8 +167,7 @@ func (c *mcentral) uncacheSpan(s *mspan) { atomic.Store(&s.sweepgen, sg) } - cap := int32((s.npages << _PageShift) / s.elemsize) - n := cap - int32(s.allocCount) + n := int(s.nelems) - int(s.allocCount) if n > 0 { // cacheSpan updated alloc assuming all objects on s // were going to be allocated. Adjust for any that |
