forked from TrueCloudLab/neoneo-go
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:
parent
f72c321426
commit
40188c5400
1 changed files with 10 additions and 4 deletions
|
@ -531,8 +531,11 @@ func (bc *Blockchain) storeBlock(block *block.Block) error {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if index >= 0 {
|
if index >= 0 {
|
||||||
copy(account.Balances[prevTXOutput.AssetID][index:], account.Balances[prevTXOutput.AssetID][index+1:])
|
last := balancesLen - 1
|
||||||
account.Balances[prevTXOutput.AssetID] = account.Balances[prevTXOutput.AssetID][: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 {
|
if err = cache.PutAccountState(account); err != nil {
|
||||||
|
@ -619,8 +622,11 @@ func (bc *Blockchain) storeBlock(block *block.Block) error {
|
||||||
var changed bool
|
var changed bool
|
||||||
for i := range acc.Unclaimed {
|
for i := range acc.Unclaimed {
|
||||||
if acc.Unclaimed[i].Tx == input.PrevHash && acc.Unclaimed[i].Index == input.PrevIndex {
|
if acc.Unclaimed[i].Tx == input.PrevHash && acc.Unclaimed[i].Index == input.PrevIndex {
|
||||||
copy(acc.Unclaimed[i:], acc.Unclaimed[i+1:])
|
last := len(acc.Unclaimed) - 1
|
||||||
acc.Unclaimed = acc.Unclaimed[:len(acc.Unclaimed)-1]
|
if last > i {
|
||||||
|
acc.Unclaimed[i] = acc.Unclaimed[last]
|
||||||
|
}
|
||||||
|
acc.Unclaimed = acc.Unclaimed[:last]
|
||||||
changed = true
|
changed = true
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue