Skip to content

Commit c6e6262

Browse files
committed
Use a slighly more performant version of VarintPure decode
1 parent 2db0708 commit c6e6262

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

lib/protobuf/varint_pure.rb

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
module Protobuf
22
module VarintPure
33
def decode(stream)
4-
value = index = 0
4+
value = shift = 0
55
begin
66
byte = stream.readbyte
7-
value |= (byte & 0x7f) << (7 * index)
8-
index += 1
9-
end while (byte & 0x80).nonzero?
7+
value |= (byte & 127) << shift
8+
shift += 7
9+
end while byte > 127
1010
value
1111
end
1212
end

0 commit comments

Comments
 (0)