@@ -14,7 +14,6 @@ import (
1414 "io"
1515 "os"
1616 "path/filepath"
17- "reflect"
1817 "runtime"
1918 "strconv"
2019 "sync/atomic"
@@ -447,26 +446,16 @@ func (s *emitState) needMetaDataFile() bool {
447446func writeMetaData (w io.Writer , metalist []rtcov.CovMetaBlob , cmode coverage.CounterMode , gran coverage.CounterGranularity , finalHash [16 ]byte ) error {
448447 mfw := encodemeta .NewCoverageMetaFileWriter ("<io.Writer>" , w )
449448
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-
456449 var blobs [][]byte
457450 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 ))
461452 blobs = append (blobs , sd )
462453 }
463454 return mfw .Write (finalHash , blobs , cmode , gran )
464455}
465456
466457func (s * emitState ) VisitFuncs (f encodecounter.CounterVisitorFn ) error {
467- var sd []atomic.Uint32
468458 var tcounters []uint32
469- bufHdr := (* reflect .SliceHeader )(unsafe .Pointer (& sd ))
470459
471460 rdCounters := func (actrs []atomic.Uint32 , ctrs []uint32 ) []uint32 {
472461 ctrs = ctrs [:0 ]
@@ -478,9 +467,7 @@ func (s *emitState) VisitFuncs(f encodecounter.CounterVisitorFn) error {
478467
479468 dpkg := uint32 (0 )
480469 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 ))
484471 for i := 0 ; i < len (sd ); i ++ {
485472 // Skip ahead until the next non-zero value.
486473 sdi := sd [i ].Load ()
0 commit comments