From e4ab996b9d0d97089b076cfef32405f5f3fedc7c Mon Sep 17 00:00:00 2001 From: Francisco Carriedo Date: Wed, 23 Jul 2014 23:55:48 -0700 Subject: [PATCH] pkg/units: Moved 'units' out of function No need to initialize every time the function executes since it works as a catalog. Docker-DCO-1.1-Signed-off-by: Francisco Carriedo (github: fcarriedo) --- pkg/units/size.go | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/pkg/units/size.go b/pkg/units/size.go index 6535540ce2..027886e5f3 100644 --- a/pkg/units/size.go +++ b/pkg/units/size.go @@ -16,17 +16,18 @@ func init() { } } +var bytePrefixes = [...]string{"B", "kB", "MB", "GB", "TB", "PB", "EB", "ZB", "YB"} + // HumanSize returns a human-readable approximation of a size // using SI standard (eg. "44kB", "17MB") func HumanSize(size int64) string { - units := []string{"B", "kB", "MB", "GB", "TB", "PB", "EB", "ZB", "YB"} i := 0 sizef := float64(size) for sizef >= 1000.0 { sizef = sizef / 1000.0 i++ } - return fmt.Sprintf("%.4g %s", sizef, units[i]) + return fmt.Sprintf("%.4g %s", sizef, bytePrefixes[i]) } // FromHumanSize returns an integer from a human-readable specification of a size