Skip to content

Commit

Permalink
Lookup all constants and set them to ivars to prevent excess const_ge…
Browse files Browse the repository at this point in the history
…ting.
  • Loading branch information
postmodern committed Apr 16, 2014
1 parent b10bb15 commit d6569db
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions lib/digest/crc.rb
Expand Up @@ -50,7 +50,10 @@ def self.pack(crc)
# Initializes the CRC checksum.
#
def initialize
@table = self.class.const_get(:TABLE)
@init_crc = self.class.const_get(:INIT_CRC)
@xor_mask = self.class.const_get(:XOR_MASK)
@width = self.class.const_get(:WIDTH)
@table = self.class.const_get(:TABLE)

reset
end
Expand All @@ -71,7 +74,7 @@ def block_length
# The length in bytes.
#
def digest_length
(self.class.const_get(:WIDTH) / 8.0).ceil
(@width / 8.0).ceil
end

#
Expand All @@ -98,7 +101,7 @@ def <<(data)
# The default value of the CRC checksum.
#
def reset
@crc = self.class.const_get(:INIT_CRC)
@crc = @init_crc
end

#
Expand All @@ -108,7 +111,7 @@ def reset
# The resulting CRC checksum.
#
def checksum
@crc ^ self.class.const_get(:XOR_MASK)
@crc ^ @xor_mask
end

#
Expand Down

0 comments on commit d6569db

Please sign in to comment.