MCPcopy Create free account
hub / github.com/apache/fory / readVarUint64Fast

Method readVarUint64Fast

go/fory/buffer.go:1177–1225  ·  view source on GitHub ↗

Fast path (when the remaining bytes are sufficient)

()

Source from the content-addressed store, hash-verified

1175
1176// Fast path (when the remaining bytes are sufficient)
1177func (b *ByteBuffer) readVarUint64Fast() uint64 {
1178 // Single instruction load using unsafe pointer cast (little-endian only)
1179 var bulk uint64
1180 if isLittleEndian {
1181 bulk = *(*uint64)(unsafe.Pointer(&b.data[b.readerIndex]))
1182 } else {
1183 bulk = binary.LittleEndian.Uint64(b.data[b.readerIndex:])
1184 }
1185
1186 result := bulk & 0x7F
1187 readLength := 1
1188
1189 if (bulk & 0x80) != 0 {
1190 result |= (bulk >> 1) & 0x3F80
1191 readLength = 2
1192 if (bulk & 0x8000) != 0 {
1193 result |= (bulk >> 2) & 0x1FC000
1194 readLength = 3
1195 if (bulk & 0x800000) != 0 {
1196 result |= (bulk >> 3) & 0xFE00000
1197 readLength = 4
1198 if (bulk & 0x80000000) != 0 {
1199 result |= (bulk >> 4) & 0x7F0000000
1200 readLength = 5
1201 if (bulk & 0x8000000000) != 0 {
1202 result |= (bulk >> 5) & 0x3F800000000
1203 readLength = 6
1204 if (bulk & 0x800000000000) != 0 {
1205 result |= (bulk >> 6) & 0x1FC0000000000
1206 readLength = 7
1207 if (bulk & 0x80000000000000) != 0 {
1208 result |= (bulk >> 7) & 0xFE000000000000
1209 readLength = 8
1210 if (bulk & 0x8000000000000000) != 0 {
1211 // Need 9th byte (full 8 bits)
1212 b9 := b.data[b.readerIndex+8]
1213 result |= uint64(b9) << 56
1214 readLength = 9
1215 }
1216 }
1217 }
1218 }
1219 }
1220 }
1221 }
1222 }
1223 b.readerIndex += readLength
1224 return result
1225}
1226
1227// Slow path (read byte by byte)
1228func (b *ByteBuffer) readVarUint64Slow(err *Error) uint64 {

Callers 3

ReadVarUint64Method · 0.95
UnsafeReadVarint64Method · 0.95
UnsafeReadVarUint64Method · 0.95

Calls 1

uint64Function · 0.50

Tested by

no test coverage detected