Convert binary Write()'s to PutUint64()'s.

PutUint64 is faster than a generic binary write, and also removes
the 'bytes' package from the import list.
This commit is contained in:
David Hill 2014-06-04 19:41:54 -04:00
parent 7f825fd9bc
commit 8bce0ef3f8

View file

@ -5,7 +5,6 @@
package main package main
import ( import (
"bytes"
"container/list" "container/list"
crand "crypto/rand" // for seeding crand "crypto/rand" // for seeding
"encoding/base32" "encoding/base32"
@ -356,12 +355,12 @@ func (a *AddrManager) getNewBucket(netAddr, srcAddr *btcwire.NetAddress) int {
hash1 := btcwire.DoubleSha256(data1) hash1 := btcwire.DoubleSha256(data1)
hash64 := binary.LittleEndian.Uint64(hash1) hash64 := binary.LittleEndian.Uint64(hash1)
hash64 %= newBucketsPerGroup hash64 %= newBucketsPerGroup
hashbuf := new(bytes.Buffer) var hashbuf [8]byte
binary.Write(hashbuf, binary.LittleEndian, hash64) binary.LittleEndian.PutUint64(hashbuf[:], hash64)
data2 := []byte{} data2 := []byte{}
data2 = append(data2, a.key[:]...) data2 = append(data2, a.key[:]...)
data2 = append(data2, GroupKey(srcAddr)...) data2 = append(data2, GroupKey(srcAddr)...)
data2 = append(data2, hashbuf.Bytes()...) data2 = append(data2, hashbuf[:]...)
hash2 := btcwire.DoubleSha256(data2) hash2 := btcwire.DoubleSha256(data2)
return int(binary.LittleEndian.Uint64(hash2) % newBucketCount) return int(binary.LittleEndian.Uint64(hash2) % newBucketCount)
@ -376,12 +375,12 @@ func (a *AddrManager) getTriedBucket(netAddr *btcwire.NetAddress) int {
hash1 := btcwire.DoubleSha256(data1) hash1 := btcwire.DoubleSha256(data1)
hash64 := binary.LittleEndian.Uint64(hash1) hash64 := binary.LittleEndian.Uint64(hash1)
hash64 %= triedBucketsPerGroup hash64 %= triedBucketsPerGroup
hashbuf := new(bytes.Buffer) var hashbuf [8]byte
binary.Write(hashbuf, binary.LittleEndian, hash64) binary.LittleEndian.PutUint64(hashbuf[:], hash64)
data2 := []byte{} data2 := []byte{}
data2 = append(data2, a.key[:]...) data2 = append(data2, a.key[:]...)
data2 = append(data2, GroupKey(netAddr)...) data2 = append(data2, GroupKey(netAddr)...)
data2 = append(data2, hashbuf.Bytes()...) data2 = append(data2, hashbuf[:]...)
hash2 := btcwire.DoubleSha256(data2) hash2 := btcwire.DoubleSha256(data2)
return int(binary.LittleEndian.Uint64(hash2) % triedBucketCount) return int(binary.LittleEndian.Uint64(hash2) % triedBucketCount)