Skip to content

Commit

Permalink
fix: account for orderedMap to be nil
Browse files Browse the repository at this point in the history
  • Loading branch information
Gabri3l committed Jun 14, 2024
1 parent 4786200 commit 8255c82
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 24 deletions.
50 changes: 26 additions & 24 deletions builtin_set.go
Original file line number Diff line number Diff line change
Expand Up @@ -394,35 +394,37 @@ func (so *setObject) MemUsage(ctx *MemUsageContext) (memUsage uint64, err error)
return memUsage, err
}

if ctx.ObjectPropsLenExceedsThreshold(so.m.size) {
inc, err := so.estimateMemUsage(ctx)
memUsage += inc
if err != nil {
return memUsage, err
}
} else {
for _, entry := range so.m.hashTable {
if entry == nil {
continue
if so.m != nil {
if ctx.ObjectPropsLenExceedsThreshold(so.m.size) {
inc, err := so.estimateMemUsage(ctx)
memUsage += inc
if err != nil {
return memUsage, err
}
} else {
for _, entry := range so.m.hashTable {
if entry == nil {
continue
}

if entry.key != nil {
inc, err := entry.key.MemUsage(ctx)
memUsage += inc
if err != nil {
return memUsage, err
if entry.key != nil {
inc, err := entry.key.MemUsage(ctx)
memUsage += inc
if err != nil {
return memUsage, err
}
}
}

if entry.value != nil {
inc, err := entry.value.MemUsage(ctx)
memUsage += inc
if err != nil {
return memUsage, err
if entry.value != nil {
inc, err := entry.value.MemUsage(ctx)
memUsage += inc
if err != nil {
return memUsage, err
}
}
if exceeded := ctx.MemUsageLimitExceeded(memUsage); exceeded {
return memUsage, nil
}
}
if exceeded := ctx.MemUsageLimitExceeded(memUsage); exceeded {
return memUsage, nil
}
}
}
Expand Down
7 changes: 7 additions & 0 deletions builtin_set_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -274,6 +274,13 @@ func TestSetObjectMemUsage(t *testing.T) {
(5+SizeString)*20,
errExpected: nil,
},
{
name: "mem is SizeEmptyStruct given a nil orderedMap object",
mu: NewMemUsageContext(vm, 88, 5000, 50, 50, 0.1, TestNativeMemUsageChecker{}),
so: &setObject{},
expectedMem: SizeEmptyStruct,
errExpected: nil,
},
}

for _, tc := range tests {
Expand Down

0 comments on commit 8255c82

Please sign in to comment.