mirror of https://github.com/status-im/consul.git
Improved performance of the version.GetHumanVersion function by 50% on memory allocation. (#11507)
Co-authored-by: Evan Culver <eculver@hashicorp.com>
This commit is contained in:
parent
71bad67a4d
commit
d013ded88d
|
@ -0,0 +1,3 @@
|
||||||
|
```release-note:improvement
|
||||||
|
version: Improved performance of the version.GetHumanVersion function by 50% on memory allocation.
|
||||||
|
```
|
|
@ -1,7 +1,6 @@
|
||||||
package version
|
package version
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
|
||||||
"strings"
|
"strings"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -29,9 +28,10 @@ func GetHumanVersion() string {
|
||||||
release := VersionPrerelease
|
release := VersionPrerelease
|
||||||
|
|
||||||
if release != "" {
|
if release != "" {
|
||||||
if !strings.HasSuffix(version, "-"+release) {
|
suffix := "-" + release
|
||||||
|
if !strings.HasSuffix(version, suffix) {
|
||||||
// if we tagged a prerelease version then the release is in the version already
|
// if we tagged a prerelease version then the release is in the version already
|
||||||
version += fmt.Sprintf("-%s", release)
|
version += suffix
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,11 @@
|
||||||
|
package version
|
||||||
|
|
||||||
|
import (
|
||||||
|
"testing"
|
||||||
|
)
|
||||||
|
|
||||||
|
func BenchmarkGetHumanVersion(b *testing.B) {
|
||||||
|
for i := 0; i < b.N; i++ {
|
||||||
|
GetHumanVersion()
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue