@@ -14,7 +14,6 @@ import (
14
14
"io"
15
15
"os"
16
16
"path/filepath"
17
- "reflect"
18
17
"runtime"
19
18
"strconv"
20
19
"sync/atomic"
@@ -447,26 +446,16 @@ func (s *emitState) needMetaDataFile() bool {
447
446
func writeMetaData (w io.Writer , metalist []rtcov.CovMetaBlob , cmode coverage.CounterMode , gran coverage.CounterGranularity , finalHash [16 ]byte ) error {
448
447
mfw := encodemeta .NewCoverageMetaFileWriter ("<io.Writer>" , w )
449
448
450
- // Note: "sd" is re-initialized on each iteration of the loop
451
- // below, and would normally be declared inside the loop, but
452
- // placed here escape analysis since we capture it in bufHdr.
453
- var sd []byte
454
- bufHdr := (* reflect .SliceHeader )(unsafe .Pointer (& sd ))
455
-
456
449
var blobs [][]byte
457
450
for _ , e := range metalist {
458
- bufHdr .Data = uintptr (unsafe .Pointer (e .P ))
459
- bufHdr .Len = int (e .Len )
460
- bufHdr .Cap = int (e .Len )
451
+ sd := unsafe .Slice (e .P , int (e .Len ))
461
452
blobs = append (blobs , sd )
462
453
}
463
454
return mfw .Write (finalHash , blobs , cmode , gran )
464
455
}
465
456
466
457
func (s * emitState ) VisitFuncs (f encodecounter.CounterVisitorFn ) error {
467
- var sd []atomic.Uint32
468
458
var tcounters []uint32
469
- bufHdr := (* reflect .SliceHeader )(unsafe .Pointer (& sd ))
470
459
471
460
rdCounters := func (actrs []atomic.Uint32 , ctrs []uint32 ) []uint32 {
472
461
ctrs = ctrs [:0 ]
@@ -478,9 +467,7 @@ func (s *emitState) VisitFuncs(f encodecounter.CounterVisitorFn) error {
478
467
479
468
dpkg := uint32 (0 )
480
469
for _ , c := range s .counterlist {
481
- bufHdr .Data = uintptr (unsafe .Pointer (c .Counters ))
482
- bufHdr .Len = int (c .Len )
483
- bufHdr .Cap = int (c .Len )
470
+ sd := unsafe .Slice ((* atomic .Uint32 )(unsafe .Pointer (c .Counters )), int (c .Len ))
484
471
for i := 0 ; i < len (sd ); i ++ {
485
472
// Skip ahead until the next non-zero value.
486
473
sdi := sd [i ].Load ()
0 commit comments