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:
Roman Khimov 2019-12-23 12:44:01 +03:00 committed by GitHub
commit 33958be45f
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -214,8 +214,9 @@ func (s *Stack) insert(e, at *Element) *Element {
func (s *Stack) updateSizeAdd(item StackItem) {
*s.size++
s.itemCount[item]++
if s.itemCount[item] > 1 {
switch item.(type) {
case *ArrayItem, *StructItem, *MapItem:
if s.itemCount[item]++; s.itemCount[item] > 1 {
return
}
@ -230,10 +231,13 @@ func (s *Stack) updateSizeAdd(item StackItem) {
}
}
}
}
func (s *Stack) updateSizeRemove(item StackItem) {
*s.size--
switch item.(type) {
case *ArrayItem, *StructItem, *MapItem:
if s.itemCount[item] > 1 {
s.itemCount[item]--
return
@ -252,6 +256,7 @@ func (s *Stack) updateSizeRemove(item StackItem) {
}
}
}
}
// InsertAt inserts the given item (n) deep on the stack.
// Be very careful using it and _always_ check both e and n before invocation