core, consensus: use slice.Clip capacity to Simplify code (#1892)

This commit is contained in:
wit liu 2026-01-05 14:46:20 +08:00 committed by GitHub
parent fb89c95640
commit 2855f1b48c
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 11 additions and 10 deletions

View file

@ -580,7 +580,7 @@ func (api *API) getRewardFileNamesInRange(begin, end *rpc.BlockNumber) ([]reward
// compact the slice's memory
ret := rewardFileNames[startIndex:endIndex]
return ret[:len(ret):len(ret)], nil
return slices.Clip(ret), nil
}
func getEpochReward(account common.Address, header *types.Header) (AccountEpochReward, error) {

View file

@ -19,6 +19,7 @@ package vm
import (
"errors"
"math/big"
"slices"
"sync/atomic"
"github.com/XinFinOrg/XDPoSChain/XDCx/tradingstate"
@ -170,20 +171,20 @@ func NewEVM(blockCtx BlockContext, txCtx TxContext, statedb StateDB, tradingStat
default:
evm.table = &frontierInstructionSet
}
var extraEips []int
if len(evm.Config.ExtraEips) > 0 {
// Deep-copy jumptable to prevent modification of opcodes in other tables
evm.table = copyJumpTable(evm.table)
}
extraEips := make([]int, 0, len(evm.Config.ExtraEips))
for _, eip := range evm.Config.ExtraEips {
if err := EnableEIP(eip, evm.table); err != nil {
// Disable it, so caller can check if it's activated or not
log.Error("EIP activation failed", "eip", eip, "error", err)
} else {
extraEips = append(extraEips, eip)
for _, eip := range evm.Config.ExtraEips {
if err := EnableEIP(eip, evm.table); err != nil {
// Disable it, so caller can check if it's activated or not
log.Error("EIP activation failed", "eip", eip, "error", err)
} else {
extraEips = append(extraEips, eip)
}
}
}
evm.Config.ExtraEips = extraEips[0:len(extraEips):len(extraEips)]
evm.Config.ExtraEips = slices.Clip(extraEips)
return evm
}