@@ -69,77 +69,50 @@ func UnmarshalString(dst []byte, str string) error {
6969 return UnmarshalBytes (dst , []byte (str ))
7070}
7171
72- func UnmarshalBytesOld (dst , src []byte ) error {
73- outi := make ([]uint32 , 4 ) // (uuidSize + 3) / 4
74-
75- for i := 0 ; i < len (src ); i ++ {
76- c := decode [src [i ]]
77-
78- for j := len (outi ) - 1 ; j >= 0 ; j -- {
79- t := uint64 (outi [j ])* 58 + c
80- c = t >> 32
81- outi [j ] = uint32 (t & 0xffffffff )
82- }
83- }
84-
85- mask := uint32 (24 ) // (((uuidSize%4) * 8) || 32) - 8
86- outLen := 0
87- for j := 0 ; j < len (outi ); j ++ {
88- for mask < 32 {
89- dst [outLen ] = byte (outi [j ] >> mask )
90- mask -= 8
91- outLen ++
92- }
93- mask = 24
94- }
95-
96- return nil
97- }
98-
9972func UnmarshalBytes (dst , src []byte ) error {
10073 // Use stack allocation for better performance
10174 var outi [4 ]uint32
102-
75+
10376 // Optimized for the common case of 22-byte base58 UUID
10477 if len (src ) == 22 {
10578 // Unrolled loop for base58 decoding
10679 // Process all 22 characters with partially unrolled loop
10780 var c uint64
108-
81+
10982 // Unroll by 2 for better performance
11083 for i := 0 ; i < 22 ; i += 2 {
11184 // First character
11285 c = decode [src [i ]]
11386 t3 := uint64 (outi [3 ])* 58 + c
11487 c = t3 >> 32
11588 outi [3 ] = uint32 (t3 )
116-
89+
11790 t2 := uint64 (outi [2 ])* 58 + c
11891 c = t2 >> 32
11992 outi [2 ] = uint32 (t2 )
120-
93+
12194 t1 := uint64 (outi [1 ])* 58 + c
12295 c = t1 >> 32
12396 outi [1 ] = uint32 (t1 )
124-
97+
12598 t0 := uint64 (outi [0 ])* 58 + c
12699 outi [0 ] = uint32 (t0 )
127-
100+
128101 // Second character (if exists)
129102 if i + 1 < 22 {
130103 c = decode [src [i + 1 ]]
131104 t3 = uint64 (outi [3 ])* 58 + c
132105 c = t3 >> 32
133106 outi [3 ] = uint32 (t3 )
134-
107+
135108 t2 = uint64 (outi [2 ])* 58 + c
136109 c = t2 >> 32
137110 outi [2 ] = uint32 (t2 )
138-
111+
139112 t1 = uint64 (outi [1 ])* 58 + c
140113 c = t1 >> 32
141114 outi [1 ] = uint32 (t1 )
142-
115+
143116 t0 = uint64 (outi [0 ])* 58 + c
144117 outi [0 ] = uint32 (t0 )
145118 }
@@ -148,31 +121,31 @@ func UnmarshalBytes(dst, src []byte) error {
148121 // Fallback for non-standard lengths
149122 for i := 0 ; i < len (src ); i ++ {
150123 c := decode [src [i ]]
151-
124+
152125 for j := 3 ; j >= 0 ; j -- {
153126 t := uint64 (outi [j ])* 58 + c
154127 c = t >> 32
155128 outi [j ] = uint32 (t )
156129 }
157130 }
158131 }
159-
132+
160133 // Unrolled output conversion
161134 dst [0 ] = byte (outi [0 ] >> 24 )
162135 dst [1 ] = byte (outi [0 ] >> 16 )
163136 dst [2 ] = byte (outi [0 ] >> 8 )
164137 dst [3 ] = byte (outi [0 ])
165-
138+
166139 dst [4 ] = byte (outi [1 ] >> 24 )
167140 dst [5 ] = byte (outi [1 ] >> 16 )
168141 dst [6 ] = byte (outi [1 ] >> 8 )
169142 dst [7 ] = byte (outi [1 ])
170-
143+
171144 dst [8 ] = byte (outi [2 ] >> 24 )
172145 dst [9 ] = byte (outi [2 ] >> 16 )
173146 dst [10 ] = byte (outi [2 ] >> 8 )
174147 dst [11 ] = byte (outi [2 ])
175-
148+
176149 dst [12 ] = byte (outi [3 ] >> 24 )
177150 dst [13 ] = byte (outi [3 ] >> 16 )
178151 dst [14 ] = byte (outi [3 ] >> 8 )
0 commit comments