@@ -16,32 +16,28 @@ limitations under the License.
16
16
17
17
package integration
18
18
19
- import "encoding/binary"
20
-
21
19
// This file is a copy of the file go/vt/sqlparser/paths.go
22
20
// We need it here to be able to test the path accumulation of the rewriter
23
21
24
22
type ASTPath string
25
23
26
- func AddStep (path ASTPath , step ASTStep ) ASTPath {
27
- b := make ([]byte , 2 )
28
- binary .BigEndian .PutUint16 (b , uint16 (step ))
29
- return path + ASTPath (b )
30
- }
31
-
32
- func AddStepWithSliceIndex (path ASTPath , step ASTStep , idx int ) ASTPath {
33
- if idx < 255 {
34
- // 2 bytes for step code + 1 byte for index
35
- b := make ([]byte , 3 )
36
- binary .BigEndian .PutUint16 (b [:2 ], uint16 (step ))
37
- b [2 ] = byte (idx )
38
- return path + ASTPath (b )
24
+ // nextPathOffset is an implementation of binary.Uvarint that works directly on
25
+ // the ASTPath without having to cast and allocate a byte slice
26
+ func (path ASTPath ) nextPathOffset () (uint64 , int ) {
27
+ var x uint64
28
+ var s uint
29
+ for i := 0 ; i < len (path ); i ++ {
30
+ b := path [i ]
31
+ if b < 0x80 {
32
+ return x | uint64 (b )<< s , i + 1
33
+ }
34
+ x |= uint64 (b & 0x7f ) << s
35
+ s += 7
39
36
}
37
+ return 0 , 0
38
+ }
40
39
41
- // 2 bytes for step code + 4 byte for index
42
- b := make ([]byte , 6 )
43
- longStep := step + 1
44
- binary .BigEndian .PutUint16 (b [:2 ], uint16 (longStep ))
45
- binary .BigEndian .PutUint32 (b [2 :], uint32 (idx ))
46
- return path + ASTPath (b )
40
+ func (path ASTPath ) nextPathStep () ASTStep {
41
+ _ = path [1 ] // bounds check hint to compiler; see golang.org/issue/14808
42
+ return ASTStep (uint16 (path [1 ]) | uint16 (path [0 ])<< 8 )
47
43
}
0 commit comments