all: simplify s[:] to s where s is a slice (#17673)

pull/17670/merge
Emil 6 years ago committed by Felix Lange
parent 7bb95a9a64
commit 86a03f97d3
  1. 2
      cmd/evm/disasm.go
  2. 2
      common/bytes.go
  3. 2
      core/chain_indexer.go
  4. 4
      core/types/bloom9.go
  5. 8
      eth/tracers/tracer.go
  6. 2
      p2p/discover/table.go
  7. 2
      p2p/discv5/table.go
  8. 14
      swarm/api/http/server_test.go
  9. 2
      swarm/pss/pss.go
  10. 10
      swarm/storage/ldbstore.go
  11. 2
      swarm/storage/ldbstore_test.go
  12. 2
      swarm/storage/types.go
  13. 2
      whisper/whisperv5/filter_test.go
  14. 2
      whisper/whisperv6/filter_test.go

@ -44,7 +44,7 @@ func disasmCmd(ctx *cli.Context) error {
return err return err
} }
code := strings.TrimSpace(string(in[:])) code := strings.TrimSpace(string(in))
fmt.Printf("%v\n", code) fmt.Printf("%v\n", code)
return asm.PrintDisassembled(code) return asm.PrintDisassembled(code)
} }

@ -100,7 +100,7 @@ func Hex2BytesFixed(str string, flen int) []byte {
return h[len(h)-flen:] return h[len(h)-flen:]
} }
hh := make([]byte, flen) hh := make([]byte, flen)
copy(hh[flen-len(h):flen], h[:]) copy(hh[flen-len(h):flen], h)
return hh return hh
} }

@ -445,7 +445,7 @@ func (c *ChainIndexer) AddChildIndexer(indexer *ChainIndexer) {
func (c *ChainIndexer) loadValidSections() { func (c *ChainIndexer) loadValidSections() {
data, _ := c.indexDb.Get([]byte("count")) data, _ := c.indexDb.Get([]byte("count"))
if len(data) == 8 { if len(data) == 8 {
c.storedSections = binary.BigEndian.Uint64(data[:]) c.storedSections = binary.BigEndian.Uint64(data)
} }
} }

@ -113,7 +113,7 @@ func LogsBloom(logs []*Log) *big.Int {
} }
func bloom9(b []byte) *big.Int { func bloom9(b []byte) *big.Int {
b = crypto.Keccak256(b[:]) b = crypto.Keccak256(b)
r := new(big.Int) r := new(big.Int)
@ -130,7 +130,7 @@ var Bloom9 = bloom9
func BloomLookup(bin Bloom, topic bytesBacked) bool { func BloomLookup(bin Bloom, topic bytesBacked) bool {
bloom := bin.Big() bloom := bin.Big()
cmp := bloom9(topic.Bytes()[:]) cmp := bloom9(topic.Bytes())
return bloom.And(bloom, cmp).Cmp(cmp) == 0 return bloom.And(bloom, cmp).Cmp(cmp) == 0
} }

@ -124,7 +124,7 @@ func (mw *memoryWrapper) pushObject(vm *duktape.Context) {
ctx.Pop2() ctx.Pop2()
ptr := ctx.PushFixedBuffer(len(blob)) ptr := ctx.PushFixedBuffer(len(blob))
copy(makeSlice(ptr, uint(len(blob))), blob[:]) copy(makeSlice(ptr, uint(len(blob))), blob)
return 1 return 1
}) })
vm.PutPropString(obj, "slice") vm.PutPropString(obj, "slice")
@ -204,7 +204,7 @@ func (dw *dbWrapper) pushObject(vm *duktape.Context) {
code := dw.db.GetCode(common.BytesToAddress(popSlice(ctx))) code := dw.db.GetCode(common.BytesToAddress(popSlice(ctx)))
ptr := ctx.PushFixedBuffer(len(code)) ptr := ctx.PushFixedBuffer(len(code))
copy(makeSlice(ptr, uint(len(code))), code[:]) copy(makeSlice(ptr, uint(len(code))), code)
return 1 return 1
}) })
vm.PutPropString(obj, "getCode") vm.PutPropString(obj, "getCode")
@ -268,7 +268,7 @@ func (cw *contractWrapper) pushObject(vm *duktape.Context) {
blob := cw.contract.Input blob := cw.contract.Input
ptr := ctx.PushFixedBuffer(len(blob)) ptr := ctx.PushFixedBuffer(len(blob))
copy(makeSlice(ptr, uint(len(blob))), blob[:]) copy(makeSlice(ptr, uint(len(blob))), blob)
return 1 return 1
}) })
vm.PutPropString(obj, "getInput") vm.PutPropString(obj, "getInput")
@ -584,7 +584,7 @@ func (jst *Tracer) GetResult() (json.RawMessage, error) {
case []byte: case []byte:
ptr := jst.vm.PushFixedBuffer(len(val)) ptr := jst.vm.PushFixedBuffer(len(val))
copy(makeSlice(ptr, uint(len(val))), val[:]) copy(makeSlice(ptr, uint(len(val))), val)
case common.Address: case common.Address:
ptr := jst.vm.PushFixedBuffer(20) ptr := jst.vm.PushFixedBuffer(20)

@ -162,7 +162,7 @@ func (tab *Table) ReadRandomNodes(buf []*Node) (n int) {
var buckets [][]*Node var buckets [][]*Node
for _, b := range &tab.buckets { for _, b := range &tab.buckets {
if len(b.entries) > 0 { if len(b.entries) > 0 {
buckets = append(buckets, b.entries[:]) buckets = append(buckets, b.entries)
} }
} }
if len(buckets) == 0 { if len(buckets) == 0 {

@ -123,7 +123,7 @@ func (tab *Table) readRandomNodes(buf []*Node) (n int) {
var buckets [][]*Node var buckets [][]*Node
for _, b := range &tab.buckets { for _, b := range &tab.buckets {
if len(b.entries) > 0 { if len(b.entries) > 0 {
buckets = append(buckets, b.entries[:]) buckets = append(buckets, b.entries)
} }
} }
if len(buckets) == 0 { if len(buckets) == 0 {

@ -501,7 +501,7 @@ func testBzzGetPath(encrypted bool, t *testing.T) {
var respbody []byte var respbody []byte
url := srv.URL + "/bzz-raw:/" url := srv.URL + "/bzz-raw:/"
if k[:] != "" { if k != "" {
url += rootRef + "/" + k[1:] + "?content_type=text/plain" url += rootRef + "/" + k[1:] + "?content_type=text/plain"
} }
resp, err = http.Get(url) resp, err = http.Get(url)
@ -515,7 +515,7 @@ func testBzzGetPath(encrypted bool, t *testing.T) {
isexpectedfailrequest := false isexpectedfailrequest := false
for _, r := range expectedfailrequests { for _, r := range expectedfailrequests {
if k[:] == r { if k == r {
isexpectedfailrequest = true isexpectedfailrequest = true
} }
} }
@ -530,7 +530,7 @@ func testBzzGetPath(encrypted bool, t *testing.T) {
var respbody []byte var respbody []byte
url := srv.URL + "/bzz-hash:/" url := srv.URL + "/bzz-hash:/"
if k[:] != "" { if k != "" {
url += rootRef + "/" + k[1:] url += rootRef + "/" + k[1:]
} }
resp, err = http.Get(url) resp, err = http.Get(url)
@ -547,7 +547,7 @@ func testBzzGetPath(encrypted bool, t *testing.T) {
isexpectedfailrequest := false isexpectedfailrequest := false
for _, r := range expectedfailrequests { for _, r := range expectedfailrequests {
if k[:] == r { if k == r {
isexpectedfailrequest = true isexpectedfailrequest = true
} }
} }
@ -599,7 +599,7 @@ func testBzzGetPath(encrypted bool, t *testing.T) {
} { } {
k := c.path k := c.path
url := srv.URL + "/bzz-list:/" url := srv.URL + "/bzz-list:/"
if k[:] != "" { if k != "" {
url += rootRef + "/" + k[1:] url += rootRef + "/" + k[1:]
} }
t.Run("json list "+c.path, func(t *testing.T) { t.Run("json list "+c.path, func(t *testing.T) {
@ -618,7 +618,7 @@ func testBzzGetPath(encrypted bool, t *testing.T) {
isexpectedfailrequest := false isexpectedfailrequest := false
for _, r := range expectedfailrequests { for _, r := range expectedfailrequests {
if k[:] == r { if k == r {
isexpectedfailrequest = true isexpectedfailrequest = true
} }
} }
@ -650,7 +650,7 @@ func testBzzGetPath(encrypted bool, t *testing.T) {
isexpectedfailrequest := false isexpectedfailrequest := false
for _, r := range expectedfailrequests { for _, r := range expectedfailrequests {
if k[:] == r { if k == r {
isexpectedfailrequest = true isexpectedfailrequest = true
} }
} }

@ -448,7 +448,7 @@ func (p *Pss) isSelfRecipient(msg *PssMsg) bool {
// test match of leftmost bytes in given message to node's Kademlia address // test match of leftmost bytes in given message to node's Kademlia address
func (p *Pss) isSelfPossibleRecipient(msg *PssMsg) bool { func (p *Pss) isSelfPossibleRecipient(msg *PssMsg) bool {
local := p.Kademlia.BaseAddr() local := p.Kademlia.BaseAddr()
return bytes.Equal(msg.To[:], local[:len(msg.To)]) return bytes.Equal(msg.To, local[:len(msg.To)])
} }
///////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////

@ -85,7 +85,7 @@ func NewLDBStoreParams(storeparams *StoreParams, path string) *LDBStoreParams {
return &LDBStoreParams{ return &LDBStoreParams{
StoreParams: storeparams, StoreParams: storeparams,
Path: path, Path: path,
Po: func(k Address) (ret uint8) { return uint8(Proximity(storeparams.BaseKey[:], k[:])) }, Po: func(k Address) (ret uint8) { return uint8(Proximity(storeparams.BaseKey, k[:])) },
} }
} }
@ -322,7 +322,7 @@ func (s *LDBStore) Export(out io.Writer) (int64, error) {
log.Trace("store.export", "dkey", fmt.Sprintf("%x", datakey), "dataidx", index.Idx, "po", po) log.Trace("store.export", "dkey", fmt.Sprintf("%x", datakey), "dataidx", index.Idx, "po", po)
data, err := s.db.Get(datakey) data, err := s.db.Get(datakey)
if err != nil { if err != nil {
log.Warn(fmt.Sprintf("Chunk %x found but could not be accessed: %v", key[:], err)) log.Warn(fmt.Sprintf("Chunk %x found but could not be accessed: %v", key, err))
continue continue
} }
@ -455,7 +455,7 @@ func (s *LDBStore) Cleanup() {
} }
if !found { if !found {
log.Warn(fmt.Sprintf("Chunk %x found but count not be accessed with any po", key[:])) log.Warn(fmt.Sprintf("Chunk %x found but count not be accessed with any po", key))
errorsFound++ errorsFound++
continue continue
} }
@ -469,10 +469,10 @@ func (s *LDBStore) Cleanup() {
} }
cs := int64(binary.LittleEndian.Uint64(c.sdata[:8])) cs := int64(binary.LittleEndian.Uint64(c.sdata[:8]))
log.Trace("chunk", "key", fmt.Sprintf("%x", key[:]), "ck", fmt.Sprintf("%x", ck), "dkey", fmt.Sprintf("%x", datakey), "dataidx", index.Idx, "po", po, "len data", len(data), "len sdata", len(c.sdata), "size", cs) log.Trace("chunk", "key", fmt.Sprintf("%x", key), "ck", fmt.Sprintf("%x", ck), "dkey", fmt.Sprintf("%x", datakey), "dataidx", index.Idx, "po", po, "len data", len(data), "len sdata", len(c.sdata), "size", cs)
if len(c.sdata) > ch.DefaultSize+8 { if len(c.sdata) > ch.DefaultSize+8 {
log.Warn("chunk for cleanup", "key", fmt.Sprintf("%x", key[:]), "ck", fmt.Sprintf("%x", ck), "dkey", fmt.Sprintf("%x", datakey), "dataidx", index.Idx, "po", po, "len data", len(data), "len sdata", len(c.sdata), "size", cs) log.Warn("chunk for cleanup", "key", fmt.Sprintf("%x", key), "ck", fmt.Sprintf("%x", ck), "dkey", fmt.Sprintf("%x", datakey), "dataidx", index.Idx, "po", po, "len data", len(data), "len sdata", len(c.sdata), "size", cs)
s.delete(index.Idx, getIndexKey(key[1:]), po) s.delete(index.Idx, getIndexKey(key[1:]), po)
removed++ removed++
errorsFound++ errorsFound++

@ -74,7 +74,7 @@ func newTestDbStore(mock bool, trusted bool) (*testDbStore, func(), error) {
func testPoFunc(k Address) (ret uint8) { func testPoFunc(k Address) (ret uint8) {
basekey := make([]byte, 32) basekey := make([]byte, 32)
return uint8(Proximity(basekey[:], k[:])) return uint8(Proximity(basekey, k[:]))
} }
func (db *testDbStore) close() { func (db *testDbStore) close() {

@ -136,7 +136,7 @@ func (a Address) Log() string {
} }
func (a Address) String() string { func (a Address) String() string {
return fmt.Sprintf("%064x", []byte(a)[:]) return fmt.Sprintf("%064x", []byte(a))
} }
func (a Address) MarshalJSON() (out []byte, err error) { func (a Address) MarshalJSON() (out []byte, err error) {

@ -56,7 +56,7 @@ func generateFilter(t *testing.T, symmetric bool) (*Filter, error) {
f.Topics = make([][]byte, topicNum) f.Topics = make([][]byte, topicNum)
for i := 0; i < topicNum; i++ { for i := 0; i < topicNum; i++ {
f.Topics[i] = make([]byte, 4) f.Topics[i] = make([]byte, 4)
mrand.Read(f.Topics[i][:]) mrand.Read(f.Topics[i])
f.Topics[i][0] = 0x01 f.Topics[i][0] = 0x01
} }

@ -56,7 +56,7 @@ func generateFilter(t *testing.T, symmetric bool) (*Filter, error) {
f.Topics = make([][]byte, topicNum) f.Topics = make([][]byte, topicNum)
for i := 0; i < topicNum; i++ { for i := 0; i < topicNum; i++ {
f.Topics[i] = make([]byte, 4) f.Topics[i] = make([]byte, 4)
mrand.Read(f.Topics[i][:]) mrand.Read(f.Topics[i])
f.Topics[i][0] = 0x01 f.Topics[i][0] = 0x01
} }

Loading…
Cancel
Save