core: get rid of unnecessary copies

There is no need to keep Balances and Unclaimed slices
sorted, we need only to remove a single element.
This commit is contained in:
Evgenii Stratonikov 2020-03-05 20:42:18 +03:00
parent f72c321426
commit 40188c5400

View file

@ -531,8 +531,11 @@ func (bc *Blockchain) storeBlock(block *block.Block) error {
}
}
if index >= 0 {
copy(account.Balances[prevTXOutput.AssetID][index:], account.Balances[prevTXOutput.AssetID][index+1:])
account.Balances[prevTXOutput.AssetID] = account.Balances[prevTXOutput.AssetID][:balancesLen-1]
last := balancesLen - 1
if last > index {
account.Balances[prevTXOutput.AssetID][index] = account.Balances[prevTXOutput.AssetID][last]
}
account.Balances[prevTXOutput.AssetID] = account.Balances[prevTXOutput.AssetID][:last]
}
}
if err = cache.PutAccountState(account); err != nil {
@ -619,8 +622,11 @@ func (bc *Blockchain) storeBlock(block *block.Block) error {
var changed bool
for i := range acc.Unclaimed {
if acc.Unclaimed[i].Tx == input.PrevHash && acc.Unclaimed[i].Index == input.PrevIndex {
copy(acc.Unclaimed[i:], acc.Unclaimed[i+1:])
acc.Unclaimed = acc.Unclaimed[:len(acc.Unclaimed)-1]
last := len(acc.Unclaimed) - 1
if last > i {
acc.Unclaimed[i] = acc.Unclaimed[last]
}
acc.Unclaimed = acc.Unclaimed[:last]
changed = true
break
}