1
0
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:
Bryan Matsuo
2015-10-10 14:00:45 -07:00
parent baeec2195c
commit 4e1e17316e
2 changed files with 4 additions and 4 deletions

View File

@@ -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
View 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.