vm: do not store items of scalar types in map

As they do not contain any other items,
they can be only accounted via total size.
This commit is contained in:
Evgenii Stratonikov 2019-12-17 11:00:40 +03:00
parent 735b937608
commit f957af35d4

View file

@ -214,19 +214,21 @@ func (s *Stack) insert(e, at *Element) *Element {
func (s *Stack) updateSizeAdd(item StackItem) { func (s *Stack) updateSizeAdd(item StackItem) {
*s.size++ *s.size++
s.itemCount[item]++ switch item.(type) {
if s.itemCount[item] > 1 { case *ArrayItem, *StructItem, *MapItem:
return if s.itemCount[item]++; s.itemCount[item] > 1 {
} return
switch t := item.(type) {
case *ArrayItem, *StructItem:
for _, it := range item.Value().([]StackItem) {
s.updateSizeAdd(it)
} }
case *MapItem:
for _, v := range t.value { switch t := item.(type) {
s.updateSizeAdd(v) 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) { func (s *Stack) updateSizeRemove(item StackItem) {
*s.size-- *s.size--
if s.itemCount[item] > 1 { switch item.(type) {
s.itemCount[item]-- case *ArrayItem, *StructItem, *MapItem:
return 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)
} }
case *MapItem:
for _, v := range t.value { delete(s.itemCount, item)
s.updateSizeRemove(v)
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)
}
} }
} }
} }