Enable prealloc linter (#607)

This commit is contained in:
Håvard Anda Estensen 2022-08-29 06:07:53 +02:00 committed by GitHub
parent e40691a4ad
commit 3b0c5f75f8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 9 additions and 8 deletions

View File

@ -23,7 +23,7 @@ linters:
- bodyclose # go1.18
- gosec
# - forcetypeassert
# - prealloc
- prealloc
# - contextcheck
# - goerr113
# - revive

View File

@ -1426,8 +1426,7 @@ func (cvt *CommitmentValTransform) commitmentValTransform(val, transValBuf commi
if err != nil {
return nil, err
}
var transAccountPks [][]byte
var transStoragePks [][]byte
transAccountPks := make([][]byte, 0, len(accountPlainKeys))
var apkBuf, spkBuf []byte
for _, accountPlainKey := range accountPlainKeys {
if len(accountPlainKey) == length.Addr {
@ -1463,6 +1462,8 @@ func (cvt *CommitmentValTransform) commitmentValTransform(val, transValBuf commi
}
transAccountPks = append(transAccountPks, accountPlainKey)
}
transStoragePks := make([][]byte, 0, len(storagePlainKeys))
for _, storagePlainKey := range storagePlainKeys {
if len(storagePlainKey) == length.Addr+length.Hash {
// Non-optimised key originating from a database record

View File

@ -141,7 +141,7 @@ func Test_BinPatriciaTrie_EmptyState(t *testing.T) {
}
func renderUpdates(branchNodeUpdates map[string]BranchData) {
var keys []string
keys := make([]string, 0, len(branchNodeUpdates))
for key := range branchNodeUpdates {
keys = append(keys, key)
}

View File

@ -487,7 +487,7 @@ func (ub *UpdateBuilder) DeleteStorage(addr string, loc string) *UpdateBuilder {
// 2. Corresponding hashed keys
// 3. Corresponding updates
func (ub *UpdateBuilder) Build() (plainKeys, hashedKeys [][]byte, updates []Update) {
var hashed []string
hashed := make([]string, 0, len(ub.keyset)+len(ub.keyset2))
preimages := make(map[string][]byte)
preimages2 := make(map[string][]byte)
keccak := sha3.NewLegacyKeccak256()

View File

@ -1003,8 +1003,8 @@ func (c *CompressorSequential) optimiseCodes() error {
}
//fmt.Printf("[comp] depth=%d, code=[%b], pattern=[%x]\n", p.depth, p.code, p.word)
}
var positionList PositionList
pos2code := make(map[uint64]*Position)
positionList := make(PositionList, 0, len(c.posMap))
pos2code := make(map[uint64]*Position, len(c.posMap))
for pos, uses := range c.posMap {
p := &Position{pos: pos, uses: uses, code: pos, codeBits: 0}
positionList = append(positionList, p)

View File

@ -500,7 +500,7 @@ func (c *Coherent) evictRoots() {
return
}
to := c.latestViewID - ViewID(c.cfg.KeepViews)
var toDel []ViewID
toDel := make([]ViewID, 0, len(c.roots))
for txID := range c.roots {
if txID > to {
continue