diff --git a/.golangci.yml b/.golangci.yml index 6a62c25cd..ad614ec62 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -23,7 +23,7 @@ linters: - bodyclose # go1.18 - gosec # - forcetypeassert -# - prealloc + - prealloc # - contextcheck # - goerr113 # - revive diff --git a/aggregator/aggregator.go b/aggregator/aggregator.go index dc3db0954..3ba9d688d 100644 --- a/aggregator/aggregator.go +++ b/aggregator/aggregator.go @@ -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 diff --git a/commitment/bin_patricia_hashed_test.go b/commitment/bin_patricia_hashed_test.go index bebcdbaf4..47526de6c 100644 --- a/commitment/bin_patricia_hashed_test.go +++ b/commitment/bin_patricia_hashed_test.go @@ -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) } diff --git a/commitment/patricia_state_mock_test.go b/commitment/patricia_state_mock_test.go index 846590494..84d2400ac 100644 --- a/commitment/patricia_state_mock_test.go +++ b/commitment/patricia_state_mock_test.go @@ -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() diff --git a/compress/compress.go b/compress/compress.go index 2463dcfec..8f1069aa7 100644 --- a/compress/compress.go +++ b/compress/compress.go @@ -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) diff --git a/kv/kvcache/cache.go b/kv/kvcache/cache.go index 8b15528df..69be19adb 100644 --- a/kv/kvcache/cache.go +++ b/kv/kvcache/cache.go @@ -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