summaryrefslogtreecommitdiff
path: root/lib/pstore.rb
diff options
context:
space:
mode:
authornobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2016-06-28 13:55:02 +0000
committernobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2016-06-28 13:55:02 +0000
commitc9df0f82b7f364e95a9cf8a9492b00759cfe61af (patch)
treecebbdad72c234ea377a7981bb2d57974a61ca42f /lib/pstore.rb
parentcafeeb4bec1a5066f5276197efb9acec14ae14b5 (diff)
PStore::CHECKSUM_ALGO
* lib/pstore.rb (PStore::CHECKSUM_ALGO): extract the algorithm for checksum, instead of qualified names for each times. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@55527 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'lib/pstore.rb')
-rw-r--r--lib/pstore.rb7
1 files changed, 4 insertions, 3 deletions
diff --git a/lib/pstore.rb b/lib/pstore.rb
index 8dfcaec7df..66a919e189 100644
--- a/lib/pstore.rb
+++ b/lib/pstore.rb
@@ -352,9 +352,10 @@ class PStore
private
# Constant for relieving Ruby's garbage collector.
+ CHECKSUM_ALGO = Digest::MD5
EMPTY_STRING = ""
EMPTY_MARSHAL_DATA = Marshal.dump({})
- EMPTY_MARSHAL_CHECKSUM = Digest::MD5.digest(EMPTY_MARSHAL_DATA)
+ EMPTY_MARSHAL_CHECKSUM = CHECKSUM_ALGO.digest(EMPTY_MARSHAL_DATA)
#
# Open the specified filename (either in read-only mode or in
@@ -409,7 +410,7 @@ class PStore
size = empty_marshal_data.bytesize
else
table = load(data)
- checksum = Digest::MD5.digest(data)
+ checksum = CHECKSUM_ALGO.digest(data)
size = data.bytesize
raise Error, "PStore file seems to be corrupted." unless table.is_a?(Hash)
end
@@ -429,7 +430,7 @@ class PStore
def save_data(original_checksum, original_file_size, file)
new_data = dump(@table)
- if new_data.bytesize != original_file_size || Digest::MD5.digest(new_data) != original_checksum
+ if new_data.bytesize != original_file_size || CHECKSUM_ALGO.digest(new_data) != original_checksum
if @ultra_safe && !on_windows?
# Windows doesn't support atomic file renames.
save_data_with_atomic_file_rename_strategy(new_data, file)