Taking a bunch of go modernize suggestions. (#4194)

This is not all of it as it is not possible (or at least I do not know
of a way) to get all suggestions for a repo/project. Did this via loop
searching mainly and taking the modernize suggestions.
This commit is contained in:
Raja Subramanian
2025-12-25 16:55:58 +05:30
committed by GitHub
parent ed8e6afcd7
commit 2510b9462e
29 changed files with 70 additions and 71 deletions
+5 -6
View File
@@ -82,7 +82,7 @@ func TestNack(t *testing.T) {
}, vp8Codec.RTPCodecCapability, 0)
rtt := uint32(20)
buff.nacker.SetRTT(rtt)
for i := 0; i < 15; i++ {
for i := range 15 {
if i == 1 {
continue
}
@@ -147,7 +147,7 @@ func TestNack(t *testing.T) {
}, vp8Codec.RTPCodecCapability, 0)
rtt := uint32(30)
buff.nacker.SetRTT(rtt)
for i := 0; i < 15; i++ {
for i := range 15 {
if i > 0 && i < 5 {
continue
}
@@ -428,15 +428,14 @@ func BenchmarkMemcpu(b *testing.B) {
buf := make([]byte, 1500*1500*10)
buf2 := make([]byte, 1500*1500*20)
b.ResetTimer()
for i := 0; i < b.N; i++ {
for b.Loop() {
copy(buf2, buf)
}
}
func BenchmarkExtPacketFactory(b *testing.B) {
b.ResetTimer()
for i := 0; i < b.N; i++ {
for b.Loop() {
extPkt := ExtPacketFactory.Get().(*ExtPacket)
*extPkt = ExtPacket{}
ExtPacketFactory.Put(extPkt)
+5 -5
View File
@@ -75,7 +75,7 @@ func createFrames(startFrameNumber uint16, startTs uint32, startSeq uint16, tota
nextTs := make([][]uint32, spatials)
tsStep := make([][]uint32, spatials)
for i := 0; i < spatials; i++ {
for i := range spatials {
nextTs[i] = make([]uint32, temporals)
tsStep[i] = make([]uint32, temporals)
for j := 0; j < temporals; j++ {
@@ -85,11 +85,11 @@ func createFrames(startFrameNumber uint16, startTs uint32, startSeq uint16, tota
}
currentTs := make([]uint32, spatials)
for i := 0; i < spatials; i++ {
for i := range spatials {
currentTs[i] = startTs
}
for i := 0; i < totalFramesPerSpatial; i++ {
for s := 0; s < spatials; s++ {
for range totalFramesPerSpatial {
for s := range spatials {
frame := &testFrameInfo{
header: rtp.Header{Timestamp: currentTs[s], SequenceNumber: startSeq},
framenumber: fn,
@@ -134,7 +134,7 @@ func createFrames(startFrameNumber uint16, startTs uint32, startSeq uint16, tota
func verifyFps(t *testing.T, expect, got []float32) {
require.Equal(t, len(expect), len(got))
for i := 0; i < len(expect); i++ {
for i := range expect {
require.GreaterOrEqual(t, got[i], expect[i]*0.9, "expect %v, got %v", expect, got)
require.LessOrEqual(t, got[i], expect[i]*1.1, "expect %v, got %v", expect, got)
}
+6 -6
View File
@@ -38,7 +38,7 @@ func (br *BitReader) ReadBits(n int) (uint, error) {
return 0, errors.New("not enough bits")
}
var v uint
for i := 0; i < n; i++ {
for range n {
bytePos := br.pos / 8
bitPos := 7 - (br.pos % 8)
bit := (br.data[bytePos] >> bitPos) & 1
@@ -108,7 +108,7 @@ func stripStartCode(b []byte) []byte {
// removeEmulationPreventionBytes removes 0x03 after 0x0000
func removeEmulationPreventionBytes(data []byte) []byte {
out := make([]byte, 0, len(data))
for i := 0; i < len(data); i++ {
for i := range data {
if i > 1 && data[i] == 0x03 && data[i-1] == 0x00 && data[i-2] == 0x00 {
continue
}
@@ -181,7 +181,7 @@ func parseH265SPS(nal []byte) (*SPSInfo, error) {
subLayerProfilePresentFlag := make([]bool, maxSubLayersMinus1)
subLayerLevelPresentFlag := make([]bool, maxSubLayersMinus1)
for i := uint(0); i < maxSubLayersMinus1; i++ {
for i := range maxSubLayersMinus1 {
f1, err := br.ReadFlag()
if err != nil {
return nil, err
@@ -201,7 +201,7 @@ func parseH265SPS(nal []byte) (*SPSInfo, error) {
}
}
}
for i := uint(0); i < maxSubLayersMinus1; i++ {
for i := range maxSubLayersMinus1 {
if subLayerProfilePresentFlag[i] {
if _, err = br.ReadBits(2 + 1 + 5); err != nil {
return nil, err
@@ -387,7 +387,7 @@ func parseH264SPS(nal []byte) (*SPSInfo, error) {
br.ReadUE() // bit_depth_chroma_minus8
br.ReadFlag() // qpprime_y_zero_transform_bypass_flag
if v, _ := br.ReadFlag(); v { // seq_scaling_matrix_present_flag
for i := 0; i < 8; i++ {
for range 8 {
br.ReadFlag()
}
}
@@ -402,7 +402,7 @@ func parseH264SPS(nal []byte) (*SPSInfo, error) {
br.ReadSE()
br.ReadSE()
cnt, _ := br.ReadUE()
for i := uint(0); i < cnt; i++ {
for range cnt {
br.ReadSE()
}
}