logtail: reduce PublicID.UnmarshalText from 2 allocs to 0

Signed-off-by: Brad Fitzpatrick <bradfitz@tailscale.com>
This commit is contained in:
Brad Fitzpatrick
2021-04-15 10:42:02 -07:00
parent bb0710d51d
commit b34fbb24e8
2 changed files with 32 additions and 6 deletions
+23
View File
@@ -303,3 +303,26 @@ func TestParseAndRemoveLogLevel(t *testing.T) {
}
}
}
func TestPublicIDUnmarshalText(t *testing.T) {
const hexStr = "6c60a9e0e7af57170bb1347b2d477e4cbc27d4571a4923b21651456f931e3d55"
x := []byte(hexStr)
var id PublicID
if err := id.UnmarshalText(x); err != nil {
t.Fatal(err)
}
if id.String() != hexStr {
t.Errorf("String = %q; want %q", id.String(), hexStr)
}
n := int(testing.AllocsPerRun(1000, func() {
var id PublicID
if err := id.UnmarshalText(x); err != nil {
t.Fatal(err)
}
}))
if n != 0 {
t.Errorf("allocs = %v; want 0", n)
}
}