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-28015: Avoid duplicate calculations in MemUsage methods #112

Merged
merged 1 commit into from
Jan 17, 2024
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
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) 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 All @@ -344,10 +345,10 @@
return 0
}
if s == "Infinity" || s == "+Infinity" {
return math.MaxInt64

Check failure on line 348 in string_ascii.go

View workflow job for this annotation

GitHub Actions / test (1.16.x, ubuntu-latest, 386)

constant 9223372036854775807 overflows int
}
if s == "-Infinity" {
return math.MinInt64

Check failure on line 351 in string_ascii.go

View workflow job for this annotation

GitHub Actions / test (1.16.x, ubuntu-latest, 386)

constant -9223372036854775808 overflows int
}
i, err := s._toInt()
if err != nil {
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
Loading