Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

BAAS-24725: Optimize visitTracker struct #101

Merged
merged 1 commit into from
Sep 19, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions array_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
10 changes: 5 additions & 5 deletions mem_context.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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 {
Expand All @@ -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 {
Expand Down Expand Up @@ -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,
Expand Down
Loading