-
Notifications
You must be signed in to change notification settings - Fork 100
Small optimizations #308
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Small optimizations #308
Changes from all commits
2db0708
c6e6262
6f007d7
48e06f8
6efe052
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,12 @@ | ||
module Protobuf | ||
module VarintPure | ||
def decode(stream) | ||
value = index = 0 | ||
value = shift = 0 | ||
begin | ||
byte = stream.readbyte | ||
value |= (byte & 0x7f) << (7 * index) | ||
index += 1 | ||
end while (byte & 0x80).nonzero? | ||
value |= (byte & 127) << shift | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Curious, is the hex actually slower than the dec? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. They're about the same, but hex is slower:
If you think it reads better as a hex (fine either way for me; google uses both), I'll change it back. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Seems pretty variable:
But I don't want to nitpick, either way is fine :). Hex is nicer for visualizing bitwise arithmetic, but I'm was mostly just curious :) |
||
shift += 7 | ||
end while byte > 127 | ||
value | ||
end | ||
end | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I could also do
@values[#{fully_qualified_field_name.inspect}]
, but I don't really have a preference.