-
-
Notifications
You must be signed in to change notification settings - Fork 29
Unified Digest::CRC#update
#41
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
Conversation
|
For reference, I am attaching the benchmark results measured on my PC.
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
lib/digest/crc.rb
Outdated
| crc = @crc | ||
|
|
||
| if self.class::REFLECT_INPUT | ||
| if @width > 8 | ||
| data.each_byte do |b| | ||
| crc = table[b ^ (0xff & crc)] ^ (crc >> 8) |
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.
If we trust each element of @table, we can make just one more speed improvement:
- crc = @crc
+ crc = @crc & ~(-1 << @width)
if self.class::REFLECT_INPUT
if @width > 8
data.each_byte do |b|
- crc = table[b ^ (0xff & crc)] ^ (crc >> 8)
+ crc = table[b ^ crc] ^ (crc >> 8)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.
Sorry, my earlier comment is wrong.
0xff & ... can be removed in three places except above.
postmodern
left a comment
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.
Minor changes requested. Need a @raise YARD tag explaining when NotImplementedError will be raised. Also some specs for that logic. Also some questions about variable naming.
|
I also noticed your using |
|
I also thought about recommending code styling changes:
|
|
Thank you for review. I will fix it. |
The generic `Digest::CRC#update` method is provided, eliminating the need to define separate `#updates` for many CRCs. However, the `Digest::CRC::REFLECT_INPUT` constant must be overridden by `true` or `false`. To speed things up a bit, the following is made: - Use local variables instead of instance variables inside loops. - Suppress generation of multi-precision integers.
57c5624 to
62995d4
Compare
The generic
Digest::CRC#updatemethod is provided, eliminating the need to define separate#updatesfor many CRCs.However, the
Digest::CRC::REFLECT_INPUTconstant must be overridden bytrueorfalse.To speed things up a bit, the following is made:
I'm not particular about the name of
REFLECT_INPUT, so if anyone has any suggestions, I'll change it.