Skip to content

Commit

Permalink
Merge pull request #96 from NETWAYS/fix/minor-alloc-optimization
Browse files Browse the repository at this point in the history
Minor allocation improvements in convert/bytes
  • Loading branch information
martialblog authored Jul 10, 2023
2 parents ea4b1a5 + 5b93213 commit 0396599
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 6 deletions.
5 changes: 2 additions & 3 deletions convert/bytes_iec.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,8 @@ const IECBase = 1024
func (b BytesIEC) HumanReadable() string {
value, unit := humanReadable(uint64(b), ByteIECUnits, IECBase)

s := strconv.FormatFloat(value, 'f', 2, 64) // nolint:gomnd
s = strings.TrimRight(s, "0") // Remove trailing zero decimals
s = strings.TrimRight(s, ".") // Remove any left over decimal dot
// Remove trailing zero decimals and any left over decimal dot
s := strings.TrimRight(strings.TrimRight(strconv.FormatFloat(value, 'f', 2, 64), "0"), ".")

return s + unit
}
Expand Down
5 changes: 2 additions & 3 deletions convert/bytes_si.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,8 @@ const SIBase = 1000
func (b BytesSI) HumanReadable() string {
value, unit := humanReadable(uint64(b), ByteSIUnits, SIBase)

s := strconv.FormatFloat(value, 'f', 2, 64) // nolint:gomnd
s = strings.TrimRight(s, "0") // Remove trailing zero decimals
s = strings.TrimRight(s, ".") // Remove any left over decimal dot
// Remove trailing zero decimals and any left over decimal dot
s := strings.TrimRight(strings.TrimRight(strconv.FormatFloat(value, 'f', 2, 64), "0"), ".")

return s + unit
}
Expand Down

0 comments on commit 0396599

Please sign in to comment.