diff options
author | Mitsuo Heijo <25817501+johejo@users.noreply.github.com> | 2021-01-05 04:17:18 +0900 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-01-04 13:17:18 -0600 |
commit | 85223faccf99409308cd169d9608753a95d21083 (patch) | |
tree | cdfd823eb1070149ae96d0823302c6e727d9f441 | |
parent | edef28d0c8acc7d3bdfaddde8ab27de602cc131b (diff) | |
download | google-uuid-85223faccf99409308cd169d9608753a95d21083.tar.gz |
Reduce custom error allocation (#70)
Zero allocation by using non-pointer error.
related #69
name old time/op new time/op delta
ParseBadLength-16 15.4ns ± 0% 3.5ns ± 0% ~ (p=1.000 n=1+1)
name old alloc/op new alloc/op delta
ParseBadLength-16 8.00B ± 0% 0.00B ~ (p=1.000 n=1+1)
name old allocs/op new allocs/op delta
ParseBadLength-16 1.00 ± 0% 0.00 ~ (p=1.000 n=1+1)
-rw-r--r-- | uuid.go | 6 |
1 files changed, 3 insertions, 3 deletions
@@ -37,7 +37,7 @@ var rander = rand.Reader // random function type invalidLengthError struct{ len int } -func (err *invalidLengthError) Error() string { +func (err invalidLengthError) Error() string { return fmt.Sprintf("invalid UUID length: %d", err.len) } @@ -74,7 +74,7 @@ func Parse(s string) (UUID, error) { } return uuid, nil default: - return uuid, &invalidLengthError{len(s)} + return uuid, invalidLengthError{len(s)} } // s is now at least 36 bytes long // it must be of the form xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx @@ -118,7 +118,7 @@ func ParseBytes(b []byte) (UUID, error) { } return uuid, nil default: - return uuid, &invalidLengthError{len(b)} + return uuid, invalidLengthError{len(b)} } // s is now at least 36 bytes long // it must be of the form xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx |