From 204f5382a1456b906f5c9a1cbf30106f05e52409 Mon Sep 17 00:00:00 2001 From: GJ Isombe Date: Mon, 18 Sep 2023 15:27:32 -0500 Subject: [PATCH] init commit Signed-off-by: GJ Isombe --- array_test.go | 5 +++-- mem_context.go | 10 +++++----- 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/array_test.go b/array_test.go index 36a31f52..9aec5498 100644 --- a/array_test.go +++ b/array_test.go @@ -190,8 +190,9 @@ func TestArrayObjectMemUsage(t *testing.T) { name: "array limit function undefined throws error", mu: &MemUsageContext{ visitTracker: visitTracker{ - objsVisited: map[objectImpl]bool{}, - stashesVisited: map[*stash]bool{}}, + objsVisited: make(map[objectImpl]struct{}), + stashesVisited: make(map[*stash]struct{}), + }, depthTracker: &depthTracker{ curDepth: 0, maxDepth: 50, diff --git a/mem_context.go b/mem_context.go index 0caddb29..fc2dcc6b 100644 --- a/mem_context.go +++ b/mem_context.go @@ -5,8 +5,8 @@ import ( ) type visitTracker struct { - objsVisited map[objectImpl]bool - stashesVisited map[*stash]bool + objsVisited map[objectImpl]struct{} + stashesVisited map[*stash]struct{} } func (vt visitTracker) IsObjVisited(obj objectImpl) bool { @@ -15,7 +15,7 @@ func (vt visitTracker) IsObjVisited(obj objectImpl) bool { } func (vt visitTracker) VisitObj(obj objectImpl) { - vt.objsVisited[obj] = true + vt.objsVisited[obj] = struct{}{} } func (vt visitTracker) IsStashVisited(stash *stash) bool { @@ -24,7 +24,7 @@ func (vt visitTracker) IsStashVisited(stash *stash) bool { } func (vt visitTracker) VisitStash(stash *stash) { - vt.stashesVisited[stash] = true + vt.stashesVisited[stash] = struct{}{} } type depthTracker struct { @@ -72,7 +72,7 @@ func NewMemUsageContext( nativeChecker NativeMemUsageChecker, ) *MemUsageContext { return &MemUsageContext{ - visitTracker: visitTracker{objsVisited: map[objectImpl]bool{}, stashesVisited: map[*stash]bool{}}, + visitTracker: visitTracker{objsVisited: make(map[objectImpl]struct{}), stashesVisited: make(map[*stash]struct{})}, depthTracker: &depthTracker{curDepth: 0, maxDepth: maxDepth}, NativeMemUsageChecker: nativeChecker, memoryLimit: memLimit,