mirror of
https://github.com/google/uuid.git
synced 2025-09-16 09:16:30 +02:00
use arrays in Parse() for reduced allocation cost and bounds checks
An array is also for hex digit value lookups which seemed to reliably give a few ns reduction in time.
This commit is contained in:
2
util.go
2
util.go
@@ -16,7 +16,7 @@ func randomBits(b []byte) {
|
||||
}
|
||||
|
||||
// xvalues returns the value of a byte as a hexadecimal digit or 255.
|
||||
var xvalues = []byte{
|
||||
var xvalues = [256]byte{
|
||||
255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
|
||||
255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
|
||||
255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
|
||||
|
6
uuid.go
Executable file → Normal file
6
uuid.go
Executable file → Normal file
@@ -54,8 +54,8 @@ func Parse(s string) UUID {
|
||||
if s[8] != '-' || s[13] != '-' || s[18] != '-' || s[23] != '-' {
|
||||
return nil
|
||||
}
|
||||
uuid := make([]byte, 16)
|
||||
for i, x := range []int{
|
||||
var uuid [16]byte
|
||||
for i, x := range [16]int{
|
||||
0, 2, 4, 6,
|
||||
9, 11,
|
||||
14, 16,
|
||||
@@ -67,7 +67,7 @@ func Parse(s string) UUID {
|
||||
uuid[i] = v
|
||||
}
|
||||
}
|
||||
return uuid
|
||||
return uuid[:]
|
||||
}
|
||||
|
||||
// Equal returns true if uuid1 and uuid2 are equal.
|
||||
|
Reference in New Issue
Block a user