From e0086dd33a4df1ae4e8bd7d8e923e4b2e1d7c963 Mon Sep 17 00:00:00 2001 From: Anton Evangelatov Date: Mon, 12 Feb 2018 21:23:59 +0100 Subject: [PATCH] swarm, pot: fix unnecessary conversions as reported by travis --- pot/address.go | 8 ++++---- swarm/network/bitvector/bitvector.go | 2 +- swarm/network/light/lightnode.go | 2 +- swarm/network/stream/delivery.go | 2 +- swarm/network/stream/stream.go | 2 +- swarm/network/stream/syncer.go | 2 +- swarm/pss/api.go | 2 +- swarm/pss/handshake.go | 2 +- swarm/storage/chunker.go | 2 +- swarm/storage/dbstore.go | 10 +++++----- swarm/storage/types.go | 2 +- 11 files changed, 18 insertions(+), 18 deletions(-) diff --git a/pot/address.go b/pot/address.go index 350f15819a..3974ebcaac 100644 --- a/pot/address.go +++ b/pot/address.go @@ -111,7 +111,7 @@ func posProximity(one, other Address, pos int) (ret int, eq bool) { start = pos % 8 } for j := start; j < 8; j++ { - if (uint8(oxo)>>uint8(7-j))&0x01 != 0 { + if (oxo>>uint8(7-j))&0x01 != 0 { return i*8 + j, false } } @@ -173,13 +173,13 @@ func RandomAddress() Address { func NewAddressFromString(s string) []byte { ha := [32]byte{} - t := s + string(zerosBin)[:len(zerosBin)-len(s)] + t := s + zerosBin[:len(zerosBin)-len(s)] for i := 0; i < 4; i++ { n, err := strconv.ParseUint(t[i*64:(i+1)*64], 2, 64) if err != nil { panic("wrong format: " + err.Error()) } - binary.BigEndian.PutUint64(ha[i*8:(i+1)*8], uint64(n)) + binary.BigEndian.PutUint64(ha[i*8:(i+1)*8], n) } return ha[:] } @@ -229,7 +229,7 @@ func proximityOrder(one, other []byte, pos int) (int, bool) { start = pos % 8 } for j := start; j < 8; j++ { - if (uint8(oxo)>>uint8(7-j))&0x01 != 0 { + if (oxo>>uint8(7-j))&0x01 != 0 { return i*8 + j, false } } diff --git a/swarm/network/bitvector/bitvector.go b/swarm/network/bitvector/bitvector.go index 256c9fd5f3..5f2f64d027 100644 --- a/swarm/network/bitvector/bitvector.go +++ b/swarm/network/bitvector/bitvector.go @@ -30,7 +30,7 @@ func NewFromBytes(b []byte, l int) (bv *BitVector, err error) { func (bv *BitVector) Get(i int) bool { bi := i / 8 - return uint8(bv.b[bi])&(0x1<= size { - return int(size - int64(off)), io.EOF + return int(size - off), io.EOF } return len(b), nil } diff --git a/swarm/storage/dbstore.go b/swarm/storage/dbstore.go index b7127bc5a3..634f79ef92 100644 --- a/swarm/storage/dbstore.go +++ b/swarm/storage/dbstore.go @@ -126,7 +126,7 @@ func NewDbStore(path string, hash SwarmHasher, capacity uint64, po func(Key) uin for i := 0; i < 0x100; i++ { k := make([]byte, 2) k[0] = keyDistanceCnt - k[1] = byte(uint8(i)) + k[1] = uint8(i) cnt, _ := s.db.Get(k) s.bucketCnt[i] = BytesToU64(cnt) s.bucketCnt[i]++ @@ -211,7 +211,7 @@ func getOldDataKey(idx uint64) []byte { func getDataKey(idx uint64, po uint8) []byte { key := make([]byte, 10) key[0] = keyData - key[1] = byte(po) + key[1] = po binary.BigEndian.PutUint64(key[2:], idx) return key @@ -483,9 +483,9 @@ func (s *DbStore) ReIndex() { oldCntKey[0] = keyDistanceCnt newCntKey[0] = keyDistanceCnt key[0] = keyData - key[1] = byte(s.po(Key(key[1:]))) + key[1] = s.po(Key(key[1:])) oldCntKey[1] = key[1] - newCntKey[1] = byte(s.po(Key(newKey[1:]))) + newCntKey[1] = s.po(Key(newKey[1:])) copy(newKey[2:], key[1:]) newValue := append(hash, data...) @@ -760,7 +760,7 @@ func (s *DbStore) SyncIterator(since uint64, until uint64, po uint8, f func(Key, for ok := it.Seek(sincekey); ok; ok = it.Next() { dbkey := it.Key() - if dbkey[0] != keyData || dbkey[1] != byte(po) || bytes.Compare(untilkey, dbkey) < 0 { + if dbkey[0] != keyData || dbkey[1] != po || bytes.Compare(untilkey, dbkey) < 0 { break } key := make([]byte, 32) diff --git a/swarm/storage/types.go b/swarm/storage/types.go index 956b8ddd8b..8de7472627 100644 --- a/swarm/storage/types.go +++ b/swarm/storage/types.go @@ -88,7 +88,7 @@ func Proximity(one, other []byte) (ret int) { m = MaxPO % 8 } for j := 0; j < m; j++ { - if (uint8(oxo)>>uint8(7-j))&0x01 != 0 { + if (oxo>>uint8(7-j))&0x01 != 0 { return i*8 + j } }