MCPcopy Create free account
hub / github.com/dolthub/doltgresql / VariableUint

Method VariableUint

utils/reader.go:129–193  ·  view source on GitHub ↗

VariableUint reads a uint64 that was written using variable-length encoding.

()

Source from the content-addressed store, hash-verified

127
128// VariableUint reads a uint64 that was written using variable-length encoding.
129func (reader *Reader) VariableUint() uint64 {
130 // This has been adapted from one of our blogs:
131 // https://www.dolthub.com/blog/2021-01-08-optimizing-varint-decoding/
132 b := uint64(reader.buf[reader.offset])
133 if b < 0x80 {
134 reader.offset += 1
135 return b
136 }
137 x := b & 0x7f
138 b = uint64(reader.buf[reader.offset+1])
139 if b < 0x80 {
140 reader.offset += 2
141 return x | (b << 7)
142 }
143 x |= (b & 0x7f) << 7
144 b = uint64(reader.buf[reader.offset+2])
145 if b < 0x80 {
146 reader.offset += 3
147 return x | (b << 14)
148 }
149 x |= (b & 0x7f) << 14
150 b = uint64(reader.buf[reader.offset+3])
151 if b < 0x80 {
152 reader.offset += 4
153 return x | (b << 21)
154 }
155 x |= (b & 0x7f) << 21
156 b = uint64(reader.buf[reader.offset+4])
157 if b < 0x80 {
158 reader.offset += 5
159 return x | (b << 28)
160 }
161 x |= (b & 0x7f) << 28
162 b = uint64(reader.buf[reader.offset+5])
163 if b < 0x80 {
164 reader.offset += 6
165 return x | (b << 35)
166 }
167 x |= (b & 0x7f) << 35
168 b = uint64(reader.buf[reader.offset+6])
169 if b < 0x80 {
170 reader.offset += 7
171 return x | (b << 42)
172 }
173 x |= (b & 0x7f) << 42
174 b = uint64(reader.buf[reader.offset+7])
175 if b < 0x80 {
176 reader.offset += 8
177 return x | (b << 49)
178 }
179 x |= (b & 0x7f) << 49
180 b = uint64(reader.buf[reader.offset+8])
181 if b < 0x80 {
182 reader.offset += 9
183 return x | (b << 56)
184 }
185 x |= (b & 0x7f) << 56
186 b = uint64(reader.buf[reader.offset+9])

Callers 15

VariableIntMethod · 0.95
StringMethod · 0.95
BoolSliceMethod · 0.95
Int8SliceMethod · 0.95
Int16SliceMethod · 0.95
Int32SliceMethod · 0.95
Int64SliceMethod · 0.95
Uint8SliceMethod · 0.95
Uint16SliceMethod · 0.95
Uint32SliceMethod · 0.95
Uint64SliceMethod · 0.95
Float32SliceMethod · 0.95

Calls

no outgoing calls

Tested by 1

TestWriterReaderFunction · 0.76