Skip to content

Commit 85223fa

Browse files
authored
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)
1 parent edef28d commit 85223fa

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

uuid.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ var rander = rand.Reader // random function
3737

3838
type invalidLengthError struct{ len int }
3939

40-
func (err *invalidLengthError) Error() string {
40+
func (err invalidLengthError) Error() string {
4141
return fmt.Sprintf("invalid UUID length: %d", err.len)
4242
}
4343

@@ -74,7 +74,7 @@ func Parse(s string) (UUID, error) {
7474
}
7575
return uuid, nil
7676
default:
77-
return uuid, &invalidLengthError{len(s)}
77+
return uuid, invalidLengthError{len(s)}
7878
}
7979
// s is now at least 36 bytes long
8080
// it must be of the form xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx
@@ -118,7 +118,7 @@ func ParseBytes(b []byte) (UUID, error) {
118118
}
119119
return uuid, nil
120120
default:
121-
return uuid, &invalidLengthError{len(b)}
121+
return uuid, invalidLengthError{len(b)}
122122
}
123123
// s is now at least 36 bytes long
124124
// it must be of the form xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx

0 commit comments

Comments
 (0)