Skip to content

Commit 3cb438f

Browse files
committed
Use Go 1.21 built-in max function
Signed-off-by: Xiaobo Liu <[email protected]>
1 parent c770c72 commit 3cb438f

File tree

5 files changed

+5
-66
lines changed

5 files changed

+5
-66
lines changed

pkg/flexfec/flexfec_encoder_03.go

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ func (flex *FlexEncoder03) encodeFlexFecPacket(fecPacketIndex uint32, mediaBaseS
141141
// Find the maximum payload size among all media packets
142142
maxPayloadSize := 0
143143
for mediaPackets.HasNext() {
144-
maxPayloadSize = maxInt(maxPayloadSize, mediaPackets.Next().MarshalSize()-BaseRTPHeaderSize)
144+
maxPayloadSize = max(maxPayloadSize, mediaPackets.Next().MarshalSize()-BaseRTPHeaderSize)
145145
}
146146
mediaPackets.Reset()
147147

@@ -239,11 +239,3 @@ func (flex *FlexEncoder03) encodeFlexFecPacket(fecPacketIndex uint32, mediaBaseS
239239

240240
return packet, true
241241
}
242-
243-
func maxInt(a, b int) int {
244-
if a > b {
245-
return a
246-
}
247-
248-
return b
249-
}

pkg/gcc/gcc.go

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,16 +6,8 @@ package gcc
66

77
import "time"
88

9-
func maxInt(a, b int) int {
10-
if a > b {
11-
return a
12-
}
13-
14-
return b
15-
}
16-
179
func clampInt(b, minVal, maxVal int) int {
18-
return maxInt(minVal, min(maxVal, b))
10+
return max(minVal, min(maxVal, b))
1911
}
2012

2113
func clampDuration(d, minVal, maxVal time.Duration) time.Duration {

pkg/gcc/gcc_test.go

Lines changed: 0 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -11,35 +11,6 @@ import (
1111
"github.com/stretchr/testify/assert"
1212
)
1313

14-
func TestMaxInt(t *testing.T) {
15-
tests := []struct {
16-
expected int
17-
a, b int
18-
}{
19-
{
20-
expected: 100,
21-
a: 0,
22-
b: 100,
23-
},
24-
{
25-
expected: 10,
26-
a: 10,
27-
b: 10,
28-
},
29-
{
30-
expected: 10,
31-
a: 10,
32-
b: 1,
33-
},
34-
}
35-
for i, tt := range tests {
36-
tt := tt
37-
t.Run(fmt.Sprintf("%v", i), func(t *testing.T) {
38-
assert.Equal(t, tt.expected, maxInt(tt.a, tt.b))
39-
})
40-
}
41-
}
42-
4314
func TestClamp(t *testing.T) {
4415
tests := []struct {
4516
expected int

pkg/twcc/arrival_time_map.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -182,9 +182,9 @@ func (m *packetArrivalTimeMap) adjustToSize(newSize int) {
182182
}
183183
m.reallocate(newCapacity)
184184
}
185-
if m.capacity() > maxInt(minCapacity, newSize*4) {
185+
if m.capacity() > max(minCapacity, newSize*4) {
186186
newCapacity := m.capacity()
187-
for newCapacity >= 2*maxInt(newSize, minCapacity) {
187+
for newCapacity >= 2*max(newSize, minCapacity) {
188188
newCapacity /= 2
189189
}
190190
m.reallocate(newCapacity)

pkg/twcc/twcc.go

Lines changed: 1 addition & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ func (r *Recorder) maybeBuildFeedbackPacket(beginSeqNumInclusive, endSeqNumExclu
134134
// It should be possible to add seq to this new packet.
135135
// If the difference between seq and beginSeqNumInclusive is too large, discard
136136
// reporting too old missing packets.
137-
baseSequenceNumber := max64(beginSeqNumInclusive, seq-maxMissingSequenceNumbers)
137+
baseSequenceNumber := max(beginSeqNumInclusive, seq-maxMissingSequenceNumbers)
138138

139139
// baseSequenceNumber is the expected first sequence number. This is known,
140140
// but we may not have actually received it, so the base time should be the time
@@ -347,19 +347,3 @@ func (c *chunk) reset() {
347347
c.hasLargeDelta = false
348348
c.hasDifferentTypes = false
349349
}
350-
351-
func maxInt(a, b int) int {
352-
if a > b {
353-
return a
354-
}
355-
356-
return b
357-
}
358-
359-
func max64(a, b int64) int64 {
360-
if a > b {
361-
return a
362-
}
363-
364-
return b
365-
}

0 commit comments

Comments
 (0)