all: use ++ to increment

Make the code slightly more idiomatic. No functional changes.

Signed-off-by: Josh Bleecher Snyder <josh@tailscale.com>
This commit is contained in:
Josh Bleecher Snyder 2020-12-22 11:38:24 -08:00 committed by Jason A. Donenfeld
parent d0f8e9477c
commit 1481e72107
5 changed files with 14 additions and 14 deletions

View File

@ -73,11 +73,11 @@ func TestTrieRandomIPv4(t *testing.T) {
const AddressLength = 4 const AddressLength = 4
for n := 0; n < NumberOfPeers; n += 1 { for n := 0; n < NumberOfPeers; n++ {
peers = append(peers, &Peer{}) peers = append(peers, &Peer{})
} }
for n := 0; n < NumberOfAddresses; n += 1 { for n := 0; n < NumberOfAddresses; n++ {
var addr [AddressLength]byte var addr [AddressLength]byte
rand.Read(addr[:]) rand.Read(addr[:])
cidr := uint(rand.Uint32() % (AddressLength * 8)) cidr := uint(rand.Uint32() % (AddressLength * 8))
@ -86,7 +86,7 @@ func TestTrieRandomIPv4(t *testing.T) {
slow = slow.Insert(addr[:], cidr, peers[index]) slow = slow.Insert(addr[:], cidr, peers[index])
} }
for n := 0; n < NumberOfTests; n += 1 { for n := 0; n < NumberOfTests; n++ {
var addr [AddressLength]byte var addr [AddressLength]byte
rand.Read(addr[:]) rand.Read(addr[:])
peer1 := slow.Lookup(addr[:]) peer1 := slow.Lookup(addr[:])
@ -106,11 +106,11 @@ func TestTrieRandomIPv6(t *testing.T) {
const AddressLength = 16 const AddressLength = 16
for n := 0; n < NumberOfPeers; n += 1 { for n := 0; n < NumberOfPeers; n++ {
peers = append(peers, &Peer{}) peers = append(peers, &Peer{})
} }
for n := 0; n < NumberOfAddresses; n += 1 { for n := 0; n < NumberOfAddresses; n++ {
var addr [AddressLength]byte var addr [AddressLength]byte
rand.Read(addr[:]) rand.Read(addr[:])
cidr := uint(rand.Uint32() % (AddressLength * 8)) cidr := uint(rand.Uint32() % (AddressLength * 8))
@ -119,7 +119,7 @@ func TestTrieRandomIPv6(t *testing.T) {
slow = slow.Insert(addr[:], cidr, peers[index]) slow = slow.Insert(addr[:], cidr, peers[index])
} }
for n := 0; n < NumberOfTests; n += 1 { for n := 0; n < NumberOfTests; n++ {
var addr [AddressLength]byte var addr [AddressLength]byte
rand.Read(addr[:]) rand.Read(addr[:])
peer1 := slow.Lookup(addr[:]) peer1 := slow.Lookup(addr[:])

View File

@ -70,11 +70,11 @@ func benchmarkTrie(peerNumber int, addressNumber int, addressLength int, b *test
const AddressLength = 4 const AddressLength = 4
for n := 0; n < peerNumber; n += 1 { for n := 0; n < peerNumber; n++ {
peers = append(peers, &Peer{}) peers = append(peers, &Peer{})
} }
for n := 0; n < addressNumber; n += 1 { for n := 0; n < addressNumber; n++ {
var addr [AddressLength]byte var addr [AddressLength]byte
rand.Read(addr[:]) rand.Read(addr[:])
cidr := uint(rand.Uint32() % (AddressLength * 8)) cidr := uint(rand.Uint32() % (AddressLength * 8))
@ -82,7 +82,7 @@ func benchmarkTrie(peerNumber int, addressNumber int, addressLength int, b *test
trie = trie.insert(addr[:], cidr, peers[index]) trie = trie.insert(addr[:], cidr, peers[index])
} }
for n := 0; n < b.N; n += 1 { for n := 0; n < b.N; n++ {
var addr [AddressLength]byte var addr [AddressLength]byte
rand.Read(addr[:]) rand.Read(addr[:])
trie.lookup(addr[:]) trie.lookup(addr[:])

View File

@ -323,7 +323,7 @@ func NewDevice(tunDevice tun.Device, logger *Logger) *Device {
cpus := runtime.NumCPU() cpus := runtime.NumCPU()
device.state.stopping.Wait() device.state.stopping.Wait()
for i := 0; i < cpus; i += 1 { for i := 0; i < cpus; i++ {
device.state.stopping.Add(2) // decryption and handshake device.state.stopping.Add(2) // decryption and handshake
go device.RoutineEncryption() go device.RoutineEncryption()
go device.RoutineDecryption() go device.RoutineDecryption()

View File

@ -26,15 +26,15 @@ func (device *Device) PopulatePools() {
} }
} else { } else {
device.pool.messageBufferReuseChan = make(chan *[MaxMessageSize]byte, PreallocatedBuffersPerPool) device.pool.messageBufferReuseChan = make(chan *[MaxMessageSize]byte, PreallocatedBuffersPerPool)
for i := 0; i < PreallocatedBuffersPerPool; i += 1 { for i := 0; i < PreallocatedBuffersPerPool; i++ {
device.pool.messageBufferReuseChan <- new([MaxMessageSize]byte) device.pool.messageBufferReuseChan <- new([MaxMessageSize]byte)
} }
device.pool.inboundElementReuseChan = make(chan *QueueInboundElement, PreallocatedBuffersPerPool) device.pool.inboundElementReuseChan = make(chan *QueueInboundElement, PreallocatedBuffersPerPool)
for i := 0; i < PreallocatedBuffersPerPool; i += 1 { for i := 0; i < PreallocatedBuffersPerPool; i++ {
device.pool.inboundElementReuseChan <- new(QueueInboundElement) device.pool.inboundElementReuseChan <- new(QueueInboundElement)
} }
device.pool.outboundElementReuseChan = make(chan *QueueOutboundElement, PreallocatedBuffersPerPool) device.pool.outboundElementReuseChan = make(chan *QueueOutboundElement, PreallocatedBuffersPerPool)
for i := 0; i < PreallocatedBuffersPerPool; i += 1 { for i := 0; i < PreallocatedBuffersPerPool; i++ {
device.pool.outboundElementReuseChan <- new(QueueOutboundElement) device.pool.outboundElementReuseChan <- new(QueueOutboundElement)
} }
} }

View File

@ -124,7 +124,7 @@ func CreateTUN(name string, mtu int) (Device, error) {
if ifIndex != -1 { if ifIndex != -1 {
tunfile, err = os.OpenFile(fmt.Sprintf("/dev/tun%d", ifIndex), unix.O_RDWR, 0) tunfile, err = os.OpenFile(fmt.Sprintf("/dev/tun%d", ifIndex), unix.O_RDWR, 0)
} else { } else {
for ifIndex = 0; ifIndex < 256; ifIndex += 1 { for ifIndex = 0; ifIndex < 256; ifIndex++ {
tunfile, err = os.OpenFile(fmt.Sprintf("/dev/tun%d", ifIndex), unix.O_RDWR, 0) tunfile, err = os.OpenFile(fmt.Sprintf("/dev/tun%d", ifIndex), unix.O_RDWR, 0)
if err == nil || !errorIsEBUSY(err) { if err == nil || !errorIsEBUSY(err) {
break break