Skip to content

Commit

Permalink
bounds check elimation in core loop
Browse files Browse the repository at this point in the history
  • Loading branch information
xtaci committed Oct 8, 2018
1 parent 90edee5 commit f48db19
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 3 deletions.
6 changes: 4 additions & 2 deletions kcp.go
Original file line number Diff line number Diff line change
Expand Up @@ -738,8 +738,10 @@ func (kcp *KCP) flush(ackOnly bool) uint32 {
current := currentMs()
var change, lost, lostSegs, fastRetransSegs, earlyRetransSegs uint64
minrto := int32(kcp.interval)
for k := range kcp.snd_buf {
segment := &kcp.snd_buf[k]

ref := kcp.snd_buf[:len(kcp.snd_buf)] // for bounds check elimination
for k := range ref {
segment := &ref[k]
needsend := false
if segment.xmit == 0 { // initial transmit
needsend = true
Expand Down
2 changes: 1 addition & 1 deletion kcp_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -287,7 +287,7 @@ func TestNetwork(t *testing.T) {

func BenchmarkFlush(b *testing.B) {
kcp := NewKCP(1, func(buf []byte, size int) {})
kcp.snd_buf = make([]segment, 32)
kcp.snd_buf = make([]segment, 1024)
for k := range kcp.snd_buf {
kcp.snd_buf[k].xmit = 1
kcp.snd_buf[k].resendts = currentMs() + 10000
Expand Down

0 comments on commit f48db19

Please sign in to comment.