Skip to content

Commit 2855f1b

Browse files
authored
core, consensus: use slice.Clip capacity to Simplify code (#1892)
1 parent fb89c95 commit 2855f1b

File tree

2 files changed

+11
-10
lines changed

2 files changed

+11
-10
lines changed

consensus/XDPoS/api.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -580,7 +580,7 @@ func (api *API) getRewardFileNamesInRange(begin, end *rpc.BlockNumber) ([]reward
580580

581581
// compact the slice's memory
582582
ret := rewardFileNames[startIndex:endIndex]
583-
return ret[:len(ret):len(ret)], nil
583+
return slices.Clip(ret), nil
584584
}
585585

586586
func getEpochReward(account common.Address, header *types.Header) (AccountEpochReward, error) {

core/vm/evm.go

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ package vm
1919
import (
2020
"errors"
2121
"math/big"
22+
"slices"
2223
"sync/atomic"
2324

2425
"github.com/XinFinOrg/XDPoSChain/XDCx/tradingstate"
@@ -170,20 +171,20 @@ func NewEVM(blockCtx BlockContext, txCtx TxContext, statedb StateDB, tradingStat
170171
default:
171172
evm.table = &frontierInstructionSet
172173
}
174+
var extraEips []int
173175
if len(evm.Config.ExtraEips) > 0 {
174176
// Deep-copy jumptable to prevent modification of opcodes in other tables
175177
evm.table = copyJumpTable(evm.table)
176-
}
177-
extraEips := make([]int, 0, len(evm.Config.ExtraEips))
178-
for _, eip := range evm.Config.ExtraEips {
179-
if err := EnableEIP(eip, evm.table); err != nil {
180-
// Disable it, so caller can check if it's activated or not
181-
log.Error("EIP activation failed", "eip", eip, "error", err)
182-
} else {
183-
extraEips = append(extraEips, eip)
178+
for _, eip := range evm.Config.ExtraEips {
179+
if err := EnableEIP(eip, evm.table); err != nil {
180+
// Disable it, so caller can check if it's activated or not
181+
log.Error("EIP activation failed", "eip", eip, "error", err)
182+
} else {
183+
extraEips = append(extraEips, eip)
184+
}
184185
}
185186
}
186-
evm.Config.ExtraEips = extraEips[0:len(extraEips):len(extraEips)]
187+
evm.Config.ExtraEips = slices.Clip(extraEips)
187188

188189
return evm
189190
}

0 commit comments

Comments
 (0)