Skip to content

Commit 86a03f9

Browse files
ludweegfjl
authored andcommitted
all: simplify s[:] to s where s is a slice (#17673)
1 parent 7bb95a9 commit 86a03f9

14 files changed

Lines changed: 28 additions & 28 deletions

File tree

‎cmd/evm/disasm.go‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ func disasmCmd(ctx *cli.Context) error {
4444
return err
4545
}
4646

47-
code := strings.TrimSpace(string(in[:]))
47+
code := strings.TrimSpace(string(in))
4848
fmt.Printf("%v\n", code)
4949
return asm.PrintDisassembled(code)
5050
}

‎common/bytes.go‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ func Hex2BytesFixed(str string, flen int) []byte {
100100
return h[len(h)-flen:]
101101
}
102102
hh := make([]byte, flen)
103-
copy(hh[flen-len(h):flen], h[:])
103+
copy(hh[flen-len(h):flen], h)
104104
return hh
105105
}
106106

‎core/chain_indexer.go‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -445,7 +445,7 @@ func (c *ChainIndexer) AddChildIndexer(indexer *ChainIndexer) {
445445
func (c *ChainIndexer) loadValidSections() {
446446
data, _ := c.indexDb.Get([]byte("count"))
447447
if len(data) == 8 {
448-
c.storedSections = binary.BigEndian.Uint64(data[:])
448+
c.storedSections = binary.BigEndian.Uint64(data)
449449
}
450450
}
451451

‎core/types/bloom9.go‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ func LogsBloom(logs []*Log) *big.Int {
113113
}
114114

115115
func bloom9(b []byte) *big.Int {
116-
b = crypto.Keccak256(b[:])
116+
b = crypto.Keccak256(b)
117117

118118
r := new(big.Int)
119119

@@ -130,7 +130,7 @@ var Bloom9 = bloom9
130130

131131
func BloomLookup(bin Bloom, topic bytesBacked) bool {
132132
bloom := bin.Big()
133-
cmp := bloom9(topic.Bytes()[:])
133+
cmp := bloom9(topic.Bytes())
134134

135135
return bloom.And(bloom, cmp).Cmp(cmp) == 0
136136
}

‎eth/tracers/tracer.go‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ func (mw *memoryWrapper) pushObject(vm *duktape.Context) {
124124
ctx.Pop2()
125125

126126
ptr := ctx.PushFixedBuffer(len(blob))
127-
copy(makeSlice(ptr, uint(len(blob))), blob[:])
127+
copy(makeSlice(ptr, uint(len(blob))), blob)
128128
return 1
129129
})
130130
vm.PutPropString(obj, "slice")
@@ -204,7 +204,7 @@ func (dw *dbWrapper) pushObject(vm *duktape.Context) {
204204
code := dw.db.GetCode(common.BytesToAddress(popSlice(ctx)))
205205

206206
ptr := ctx.PushFixedBuffer(len(code))
207-
copy(makeSlice(ptr, uint(len(code))), code[:])
207+
copy(makeSlice(ptr, uint(len(code))), code)
208208
return 1
209209
})
210210
vm.PutPropString(obj, "getCode")
@@ -268,7 +268,7 @@ func (cw *contractWrapper) pushObject(vm *duktape.Context) {
268268
blob := cw.contract.Input
269269

270270
ptr := ctx.PushFixedBuffer(len(blob))
271-
copy(makeSlice(ptr, uint(len(blob))), blob[:])
271+
copy(makeSlice(ptr, uint(len(blob))), blob)
272272
return 1
273273
})
274274
vm.PutPropString(obj, "getInput")
@@ -584,7 +584,7 @@ func (jst *Tracer) GetResult() (json.RawMessage, error) {
584584

585585
case []byte:
586586
ptr := jst.vm.PushFixedBuffer(len(val))
587-
copy(makeSlice(ptr, uint(len(val))), val[:])
587+
copy(makeSlice(ptr, uint(len(val))), val)
588588

589589
case common.Address:
590590
ptr := jst.vm.PushFixedBuffer(20)

‎p2p/discover/table.go‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,7 @@ func (tab *Table) ReadRandomNodes(buf []*Node) (n int) {
162162
var buckets [][]*Node
163163
for _, b := range &tab.buckets {
164164
if len(b.entries) > 0 {
165-
buckets = append(buckets, b.entries[:])
165+
buckets = append(buckets, b.entries)
166166
}
167167
}
168168
if len(buckets) == 0 {

‎p2p/discv5/table.go‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ func (tab *Table) readRandomNodes(buf []*Node) (n int) {
123123
var buckets [][]*Node
124124
for _, b := range &tab.buckets {
125125
if len(b.entries) > 0 {
126-
buckets = append(buckets, b.entries[:])
126+
buckets = append(buckets, b.entries)
127127
}
128128
}
129129
if len(buckets) == 0 {

‎swarm/api/http/server_test.go‎

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -501,7 +501,7 @@ func testBzzGetPath(encrypted bool, t *testing.T) {
501501
var respbody []byte
502502

503503
url := srv.URL + "/bzz-raw:/"
504-
if k[:] != "" {
504+
if k != "" {
505505
url += rootRef + "/" + k[1:] + "?content_type=text/plain"
506506
}
507507
resp, err = http.Get(url)
@@ -515,7 +515,7 @@ func testBzzGetPath(encrypted bool, t *testing.T) {
515515
isexpectedfailrequest := false
516516

517517
for _, r := range expectedfailrequests {
518-
if k[:] == r {
518+
if k == r {
519519
isexpectedfailrequest = true
520520
}
521521
}
@@ -530,7 +530,7 @@ func testBzzGetPath(encrypted bool, t *testing.T) {
530530
var respbody []byte
531531

532532
url := srv.URL + "/bzz-hash:/"
533-
if k[:] != "" {
533+
if k != "" {
534534
url += rootRef + "/" + k[1:]
535535
}
536536
resp, err = http.Get(url)
@@ -547,7 +547,7 @@ func testBzzGetPath(encrypted bool, t *testing.T) {
547547
isexpectedfailrequest := false
548548

549549
for _, r := range expectedfailrequests {
550-
if k[:] == r {
550+
if k == r {
551551
isexpectedfailrequest = true
552552
}
553553
}
@@ -599,7 +599,7 @@ func testBzzGetPath(encrypted bool, t *testing.T) {
599599
} {
600600
k := c.path
601601
url := srv.URL + "/bzz-list:/"
602-
if k[:] != "" {
602+
if k != "" {
603603
url += rootRef + "/" + k[1:]
604604
}
605605
t.Run("json list "+c.path, func(t *testing.T) {
@@ -618,7 +618,7 @@ func testBzzGetPath(encrypted bool, t *testing.T) {
618618
isexpectedfailrequest := false
619619

620620
for _, r := range expectedfailrequests {
621-
if k[:] == r {
621+
if k == r {
622622
isexpectedfailrequest = true
623623
}
624624
}
@@ -650,7 +650,7 @@ func testBzzGetPath(encrypted bool, t *testing.T) {
650650
isexpectedfailrequest := false
651651

652652
for _, r := range expectedfailrequests {
653-
if k[:] == r {
653+
if k == r {
654654
isexpectedfailrequest = true
655655
}
656656
}

‎swarm/pss/pss.go‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -448,7 +448,7 @@ func (p *Pss) isSelfRecipient(msg *PssMsg) bool {
448448
// test match of leftmost bytes in given message to node's Kademlia address
449449
func (p *Pss) isSelfPossibleRecipient(msg *PssMsg) bool {
450450
local := p.Kademlia.BaseAddr()
451-
return bytes.Equal(msg.To[:], local[:len(msg.To)])
451+
return bytes.Equal(msg.To, local[:len(msg.To)])
452452
}
453453

454454
/////////////////////////////////////////////////////////////////////

‎swarm/storage/ldbstore.go‎

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ func NewLDBStoreParams(storeparams *StoreParams, path string) *LDBStoreParams {
8585
return &LDBStoreParams{
8686
StoreParams: storeparams,
8787
Path: path,
88-
Po: func(k Address) (ret uint8) { return uint8(Proximity(storeparams.BaseKey[:], k[:])) },
88+
Po: func(k Address) (ret uint8) { return uint8(Proximity(storeparams.BaseKey, k[:])) },
8989
}
9090
}
9191

@@ -322,7 +322,7 @@ func (s *LDBStore) Export(out io.Writer) (int64, error) {
322322
log.Trace("store.export", "dkey", fmt.Sprintf("%x", datakey), "dataidx", index.Idx, "po", po)
323323
data, err := s.db.Get(datakey)
324324
if err != nil {
325-
log.Warn(fmt.Sprintf("Chunk %x found but could not be accessed: %v", key[:], err))
325+
log.Warn(fmt.Sprintf("Chunk %x found but could not be accessed: %v", key, err))
326326
continue
327327
}
328328

@@ -455,7 +455,7 @@ func (s *LDBStore) Cleanup() {
455455
}
456456

457457
if !found {
458-
log.Warn(fmt.Sprintf("Chunk %x found but count not be accessed with any po", key[:]))
458+
log.Warn(fmt.Sprintf("Chunk %x found but count not be accessed with any po", key))
459459
errorsFound++
460460
continue
461461
}
@@ -469,10 +469,10 @@ func (s *LDBStore) Cleanup() {
469469
}
470470

471471
cs := int64(binary.LittleEndian.Uint64(c.sdata[:8]))
472-
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)
472+
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)
473473

474474
if len(c.sdata) > ch.DefaultSize+8 {
475-
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)
475+
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)
476476
s.delete(index.Idx, getIndexKey(key[1:]), po)
477477
removed++
478478
errorsFound++

0 commit comments

Comments
 (0)