Skip to content

Commit

Permalink
BAAS-28015: Avoid duplicate calculations in MemUsage methods (#112)
Browse files Browse the repository at this point in the history
  • Loading branch information
Calvinnix authored Jan 17, 2024
1 parent ece6fc6 commit b6ea3a7
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 4 deletions.
3 changes: 2 additions & 1 deletion string_ascii.go
Original file line number Diff line number Diff line change
Expand Up @@ -336,7 +336,8 @@ func (s asciiString) ExportType() reflect.Type {
}

func (s asciiString) MemUsage(ctx *MemUsageContext) (memUsage uint64, newMemUsage uint64, err error) {
return uint64(s.length()) + SizeString, uint64(s.length()) + SizeString, err
asciiStringLength := uint64(s.length())
return asciiStringLength + SizeString, asciiStringLength + SizeString, err
}

func (s asciiString) ToInt() int {
Expand Down
3 changes: 2 additions & 1 deletion string_imported.go
Original file line number Diff line number Diff line change
Expand Up @@ -351,5 +351,6 @@ func (i *importedString) toTrimmedUTF8() string {
}

func (i *importedString) MemUsage(ctx *MemUsageContext) (memUsage uint64, newMemUsage uint64, err error) {
return uint64(len(i.String())) + SizeString, uint64(len(i.String())) + SizeString, err
importedStringLength := uint64(len(i.String()))
return importedStringLength + SizeString, importedStringLength + SizeString, err
}
3 changes: 2 additions & 1 deletion string_unicode.go
Original file line number Diff line number Diff line change
Expand Up @@ -560,7 +560,8 @@ func (s unicodeString) string() unistring.String {
}

func (s unicodeString) MemUsage(ctx *MemUsageContext) (memUsage uint64, newMemUsage uint64, err error) {
return uint64(len(s.String())) + SizeString, uint64(len(s.String())) + SizeString, err
stringLength := uint64(len(s.String()))
return stringLength + SizeString, stringLength + SizeString, err
}
func (s unicodeString) ToInt() int {
return 0
Expand Down
3 changes: 2 additions & 1 deletion value.go
Original file line number Diff line number Diff line change
Expand Up @@ -1486,7 +1486,8 @@ func (o valueUnresolved) hash(*maphash.Hash) uint64 {
}

func (o valueUnresolved) MemUsage(ctx *MemUsageContext) (memUsage uint64, newMemUsage uint64, err error) {
return uint64(len(o.ref)) + SizeString, uint64(len(o.ref)) + SizeString, nil
refLength := uint64(len(o.ref))
return refLength + SizeString, refLength + SizeString, nil
}

func (o valueUnresolved) ToInt() int {
Expand Down

0 comments on commit b6ea3a7

Please sign in to comment.