mirror of
https://github.com/tailscale/tailscale.git
synced 2025-10-25 10:09:17 +00:00
types/wgkey: simplify Key.UnmarshalJSON
Instead of calling ParseHex, do the hex.Decode directly. name old time/op new time/op delta UnmarshalJSON-8 86.9ns ± 0% 42.6ns ± 0% -50.94% (p=0.000 n=15+14) name old alloc/op new alloc/op delta UnmarshalJSON-8 128B ± 0% 0B -100.00% (p=0.000 n=15+15) name old allocs/op new allocs/op delta UnmarshalJSON-8 2.00 ± 0% 0.00 -100.00% (p=0.000 n=15+15) Signed-off-by: Josh Bleecher Snyder <josh@tailscale.com>
This commit is contained in:
@@ -106,11 +106,10 @@ func (k *Key) UnmarshalJSON(b []byte) error {
|
||||
return errors.New("wgkey.Key: UnmarshalJSON not given a string")
|
||||
}
|
||||
b = b[1 : len(b)-1]
|
||||
key, err := ParseHex(string(b))
|
||||
if err != nil {
|
||||
return fmt.Errorf("wgkey.Key: UnmarshalJSON: %v", err)
|
||||
if len(b) != 2*Size {
|
||||
return fmt.Errorf("wgkey.Key: UnmarshalJSON input wrong size: %d", len(b))
|
||||
}
|
||||
copy(k[:], key[:])
|
||||
hex.Decode(k[:], b)
|
||||
return nil
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user