mirror of
https://github.com/nspcc-dev/neo-go.git
synced 2024-12-23 23:25:22 +00:00
Merge pull request #559 from nspcc-dev/feature/stack_limits
vm: don't refcount simple items Improves 1.4M to 1.5M 100K mainnet block import test by ~4%.
This commit is contained in:
commit
33958be45f
1 changed files with 31 additions and 26 deletions
|
@ -214,19 +214,21 @@ func (s *Stack) insert(e, at *Element) *Element {
|
|||
func (s *Stack) updateSizeAdd(item StackItem) {
|
||||
*s.size++
|
||||
|
||||
s.itemCount[item]++
|
||||
if s.itemCount[item] > 1 {
|
||||
return
|
||||
}
|
||||
|
||||
switch t := item.(type) {
|
||||
case *ArrayItem, *StructItem:
|
||||
for _, it := range item.Value().([]StackItem) {
|
||||
s.updateSizeAdd(it)
|
||||
switch item.(type) {
|
||||
case *ArrayItem, *StructItem, *MapItem:
|
||||
if s.itemCount[item]++; s.itemCount[item] > 1 {
|
||||
return
|
||||
}
|
||||
case *MapItem:
|
||||
for _, v := range t.value {
|
||||
s.updateSizeAdd(v)
|
||||
|
||||
switch t := item.(type) {
|
||||
case *ArrayItem, *StructItem:
|
||||
for _, it := range item.Value().([]StackItem) {
|
||||
s.updateSizeAdd(it)
|
||||
}
|
||||
case *MapItem:
|
||||
for _, v := range t.value {
|
||||
s.updateSizeAdd(v)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -234,21 +236,24 @@ func (s *Stack) updateSizeAdd(item StackItem) {
|
|||
func (s *Stack) updateSizeRemove(item StackItem) {
|
||||
*s.size--
|
||||
|
||||
if s.itemCount[item] > 1 {
|
||||
s.itemCount[item]--
|
||||
return
|
||||
}
|
||||
|
||||
delete(s.itemCount, item)
|
||||
|
||||
switch t := item.(type) {
|
||||
case *ArrayItem, *StructItem:
|
||||
for _, it := range item.Value().([]StackItem) {
|
||||
s.updateSizeRemove(it)
|
||||
switch item.(type) {
|
||||
case *ArrayItem, *StructItem, *MapItem:
|
||||
if s.itemCount[item] > 1 {
|
||||
s.itemCount[item]--
|
||||
return
|
||||
}
|
||||
case *MapItem:
|
||||
for _, v := range t.value {
|
||||
s.updateSizeRemove(v)
|
||||
|
||||
delete(s.itemCount, item)
|
||||
|
||||
switch t := item.(type) {
|
||||
case *ArrayItem, *StructItem:
|
||||
for _, it := range item.Value().([]StackItem) {
|
||||
s.updateSizeRemove(it)
|
||||
}
|
||||
case *MapItem:
|
||||
for _, v := range t.value {
|
||||
s.updateSizeRemove(v)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue