mirror of
https://github.com/golang/go.git
synced 2025-05-05 23:53:05 +00:00
runtime/coverage: use unsafe.Slice, not reflect.SliceHeader
Change-Id: I59c4757df83c12b4c8b85cdd523552c5e5e7bf95 Reviewed-on: https://go-review.googlesource.com/c/go/+/508977 Reviewed-by: Ian Lance Taylor <iant@google.com> Auto-Submit: Ian Lance Taylor <iant@google.com> TryBot-Result: Gopher Robot <gobot@golang.org> Run-TryBot: Ian Lance Taylor <iant@google.com> Run-TryBot: Ian Lance Taylor <iant@golang.org> Reviewed-by: Than McIntosh <thanm@google.com>
This commit is contained in:
parent
eaa8419a72
commit
88a545d844
@ -8,7 +8,6 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
"internal/coverage"
|
"internal/coverage"
|
||||||
"io"
|
"io"
|
||||||
"reflect"
|
|
||||||
"sync/atomic"
|
"sync/atomic"
|
||||||
"unsafe"
|
"unsafe"
|
||||||
)
|
)
|
||||||
@ -158,13 +157,8 @@ func ClearCounters() error {
|
|||||||
// inconsistency when reading the counter array from the thread
|
// inconsistency when reading the counter array from the thread
|
||||||
// running ClearCounters.
|
// running ClearCounters.
|
||||||
|
|
||||||
var sd []atomic.Uint32
|
|
||||||
|
|
||||||
bufHdr := (*reflect.SliceHeader)(unsafe.Pointer(&sd))
|
|
||||||
for _, c := range cl {
|
for _, c := range cl {
|
||||||
bufHdr.Data = uintptr(unsafe.Pointer(c.Counters))
|
sd := unsafe.Slice((*atomic.Uint32)(unsafe.Pointer(c.Counters)), int(c.Len))
|
||||||
bufHdr.Len = int(c.Len)
|
|
||||||
bufHdr.Cap = int(c.Len)
|
|
||||||
for i := 0; i < len(sd); i++ {
|
for i := 0; i < len(sd); i++ {
|
||||||
// Skip ahead until the next non-zero value.
|
// Skip ahead until the next non-zero value.
|
||||||
sdi := sd[i].Load()
|
sdi := sd[i].Load()
|
||||||
|
@ -14,7 +14,6 @@ import (
|
|||||||
"io"
|
"io"
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"reflect"
|
|
||||||
"runtime"
|
"runtime"
|
||||||
"strconv"
|
"strconv"
|
||||||
"sync/atomic"
|
"sync/atomic"
|
||||||
@ -447,26 +446,16 @@ func (s *emitState) needMetaDataFile() bool {
|
|||||||
func writeMetaData(w io.Writer, metalist []rtcov.CovMetaBlob, cmode coverage.CounterMode, gran coverage.CounterGranularity, finalHash [16]byte) error {
|
func writeMetaData(w io.Writer, metalist []rtcov.CovMetaBlob, cmode coverage.CounterMode, gran coverage.CounterGranularity, finalHash [16]byte) error {
|
||||||
mfw := encodemeta.NewCoverageMetaFileWriter("<io.Writer>", w)
|
mfw := encodemeta.NewCoverageMetaFileWriter("<io.Writer>", w)
|
||||||
|
|
||||||
// Note: "sd" is re-initialized on each iteration of the loop
|
|
||||||
// below, and would normally be declared inside the loop, but
|
|
||||||
// placed here escape analysis since we capture it in bufHdr.
|
|
||||||
var sd []byte
|
|
||||||
bufHdr := (*reflect.SliceHeader)(unsafe.Pointer(&sd))
|
|
||||||
|
|
||||||
var blobs [][]byte
|
var blobs [][]byte
|
||||||
for _, e := range metalist {
|
for _, e := range metalist {
|
||||||
bufHdr.Data = uintptr(unsafe.Pointer(e.P))
|
sd := unsafe.Slice(e.P, int(e.Len))
|
||||||
bufHdr.Len = int(e.Len)
|
|
||||||
bufHdr.Cap = int(e.Len)
|
|
||||||
blobs = append(blobs, sd)
|
blobs = append(blobs, sd)
|
||||||
}
|
}
|
||||||
return mfw.Write(finalHash, blobs, cmode, gran)
|
return mfw.Write(finalHash, blobs, cmode, gran)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *emitState) VisitFuncs(f encodecounter.CounterVisitorFn) error {
|
func (s *emitState) VisitFuncs(f encodecounter.CounterVisitorFn) error {
|
||||||
var sd []atomic.Uint32
|
|
||||||
var tcounters []uint32
|
var tcounters []uint32
|
||||||
bufHdr := (*reflect.SliceHeader)(unsafe.Pointer(&sd))
|
|
||||||
|
|
||||||
rdCounters := func(actrs []atomic.Uint32, ctrs []uint32) []uint32 {
|
rdCounters := func(actrs []atomic.Uint32, ctrs []uint32) []uint32 {
|
||||||
ctrs = ctrs[:0]
|
ctrs = ctrs[:0]
|
||||||
@ -478,9 +467,7 @@ func (s *emitState) VisitFuncs(f encodecounter.CounterVisitorFn) error {
|
|||||||
|
|
||||||
dpkg := uint32(0)
|
dpkg := uint32(0)
|
||||||
for _, c := range s.counterlist {
|
for _, c := range s.counterlist {
|
||||||
bufHdr.Data = uintptr(unsafe.Pointer(c.Counters))
|
sd := unsafe.Slice((*atomic.Uint32)(unsafe.Pointer(c.Counters)), int(c.Len))
|
||||||
bufHdr.Len = int(c.Len)
|
|
||||||
bufHdr.Cap = int(c.Len)
|
|
||||||
for i := 0; i < len(sd); i++ {
|
for i := 0; i < len(sd); i++ {
|
||||||
// Skip ahead until the next non-zero value.
|
// Skip ahead until the next non-zero value.
|
||||||
sdi := sd[i].Load()
|
sdi := sd[i].Load()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user