Improved box checksum verification performance
When adding large boxes verifying the checksum took noticably longer than expected because the Ruby GC was needlessly working overtime.
This commit is contained in:
parent
1e28f1ac31
commit
9c20014a85
|
@ -8,7 +8,7 @@ class DigestClass
|
||||||
end
|
end
|
||||||
|
|
||||||
class FileChecksum
|
class FileChecksum
|
||||||
BUFFER_SIZE = 16328
|
BUFFER_SIZE = 1024 * 8
|
||||||
|
|
||||||
# Initializes an object to calculate the checksum of a file. The given
|
# Initializes an object to calculate the checksum of a file. The given
|
||||||
# ``digest_klass`` should implement the ``DigestClass`` interface. Note
|
# ``digest_klass`` should implement the ``DigestClass`` interface. Note
|
||||||
|
@ -25,11 +25,12 @@ class FileChecksum
|
||||||
# @return [String]
|
# @return [String]
|
||||||
def checksum
|
def checksum
|
||||||
digest = @digest_klass.new
|
digest = @digest_klass.new
|
||||||
|
buf = ''
|
||||||
|
|
||||||
File.open(@path, "rb") do |f|
|
File.open(@path, "rb") do |f|
|
||||||
while !f.eof
|
while !f.eof
|
||||||
begin
|
begin
|
||||||
buf = f.readpartial(BUFFER_SIZE)
|
f.readpartial(BUFFER_SIZE, buf)
|
||||||
digest.update(buf)
|
digest.update(buf)
|
||||||
rescue EOFError
|
rescue EOFError
|
||||||
# Although we check for EOF earlier, this seems to happen
|
# Although we check for EOF earlier, this seems to happen
|
||||||
|
|
Loading…
Reference in New Issue