Skip to content

Commit b6aeff3

Browse files
committed
fix integration tests
Signed-off-by: Vicent Marti <vmg@strn.cat>
1 parent 9070230 commit b6aeff3

File tree

1 file changed

+17
-21
lines changed
  • go/tools/asthelpergen/integration

1 file changed

+17
-21
lines changed

go/tools/asthelpergen/integration/paths.go

Lines changed: 17 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -16,32 +16,28 @@ limitations under the License.
1616

1717
package integration
1818

19-
import "encoding/binary"
20-
2119
// This file is a copy of the file go/vt/sqlparser/paths.go
2220
// We need it here to be able to test the path accumulation of the rewriter
2321

2422
type ASTPath string
2523

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
3936
}
37+
return 0, 0
38+
}
4039

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)
4743
}

0 commit comments

Comments
 (0)