Skip to content

Commit

Permalink
BAAS-32009: add defer to all ctx.Ascend() calls in realm (#125)
Browse files Browse the repository at this point in the history
  • Loading branch information
zhouselena authored Jun 28, 2024
1 parent fbae8e7 commit 1023e46
Show file tree
Hide file tree
Showing 6 changed files with 6 additions and 13 deletions.
3 changes: 1 addition & 2 deletions array.go
Original file line number Diff line number Diff line change
Expand Up @@ -623,6 +623,7 @@ func (a *arrayObject) MemUsage(ctx *MemUsageContext) (memUsage uint64, err error
if err := ctx.Descend(); err != nil {
return memUsage, err
}
defer ctx.Ascend()

if ctx.ArrayLenExceedsThreshold == nil {
return memUsage, errArrayLenExceedsThresholdNil
Expand All @@ -640,7 +641,6 @@ func (a *arrayObject) MemUsage(ctx *MemUsageContext) (memUsage uint64, err error
return memUsage, err
}

ctx.Ascend()
return memUsage, nil
}

Expand All @@ -661,6 +661,5 @@ func (a *arrayObject) MemUsage(ctx *MemUsageContext) (memUsage uint64, err error
}
}

ctx.Ascend()
return memUsage, nil
}
4 changes: 1 addition & 3 deletions array_sparse.go
Original file line number Diff line number Diff line change
Expand Up @@ -535,6 +535,7 @@ func (a *sparseArrayObject) MemUsage(ctx *MemUsageContext) (memUsage uint64, err
if err := ctx.Descend(); err != nil {
return SizeEmptyStruct, err
}
defer ctx.Ascend()

// sparseArrayObject overhead
memUsage = SizeEmptyStruct
Expand All @@ -552,7 +553,6 @@ func (a *sparseArrayObject) MemUsage(ctx *MemUsageContext) (memUsage uint64, err
return memUsage, err
}

ctx.Ascend()
return memUsage, nil
}

Expand All @@ -571,7 +571,5 @@ func (a *sparseArrayObject) MemUsage(ctx *MemUsageContext) (memUsage uint64, err
}
}

ctx.Ascend()

return memUsage, err
}
3 changes: 1 addition & 2 deletions builtin_map.go
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,7 @@ func (mo *mapObject) MemUsage(ctx *MemUsageContext) (memUsage uint64, err error)
if err := ctx.Descend(); err != nil {
return memUsage, err
}
defer ctx.Ascend()

memUsage, err = mo.baseObject.MemUsage(ctx)
if err != nil {
Expand Down Expand Up @@ -176,8 +177,6 @@ func (mo *mapObject) MemUsage(ctx *MemUsageContext) (memUsage uint64, err error)
}
}

ctx.Ascend()

return memUsage, nil
}

Expand Down
3 changes: 1 addition & 2 deletions builtin_set.go
Original file line number Diff line number Diff line change
Expand Up @@ -393,6 +393,7 @@ func (so *setObject) MemUsage(ctx *MemUsageContext) (memUsage uint64, err error)
if err := ctx.Descend(); err != nil {
return memUsage, err
}
defer ctx.Ascend()

memUsage, err = so.baseObject.MemUsage(ctx)
if err != nil {
Expand Down Expand Up @@ -434,7 +435,5 @@ func (so *setObject) MemUsage(ctx *MemUsageContext) (memUsage uint64, err error)
}
}

ctx.Ascend()

return memUsage, nil
}
3 changes: 1 addition & 2 deletions object.go
Original file line number Diff line number Diff line change
Expand Up @@ -1946,6 +1946,7 @@ func (o *baseObject) MemUsage(ctx *MemUsageContext) (memUsage uint64, err error)
if err := ctx.Descend(); err != nil {
return 0, err
}
defer ctx.Ascend()

memUsage = SizeEmptyStruct
if ctx.ObjectPropsLenExceedsThreshold(len(o.propNames)) {
Expand Down Expand Up @@ -1981,8 +1982,6 @@ func (o *baseObject) MemUsage(ctx *MemUsageContext) (memUsage uint64, err error)
}
}

ctx.Ascend()

return memUsage, nil
}

Expand Down
3 changes: 1 addition & 2 deletions proxy.go
Original file line number Diff line number Diff line change
Expand Up @@ -1063,6 +1063,7 @@ func (p *proxyObject) MemUsage(ctx *MemUsageContext) (memUsage uint64, err error
if err := ctx.Descend(); err != nil {
return 0, err
}
defer ctx.Ascend()

memUsage = SizeEmptyStruct
inc, err := p.baseObject.MemUsage(ctx)
Expand All @@ -1087,8 +1088,6 @@ func (p *proxyObject) MemUsage(ctx *MemUsageContext) (memUsage uint64, err error
}
}

ctx.Ascend()

return memUsage, nil
}

Expand Down

0 comments on commit 1023e46

Please sign in to comment.