diff options
author | nobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2016-06-28 13:55:02 +0000 |
---|---|---|
committer | nobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2016-06-28 13:55:02 +0000 |
commit | 0721ed92ac9cd87beb6c99563b5f8b08590b5369 (patch) | |
tree | cebbdad72c234ea377a7981bb2d57974a61ca42f | |
parent | 88f7fc294729500ff17ff0367386fac46eb9ad84 (diff) | |
download | ruby-0721ed92ac9cd87beb6c99563b5f8b08590b5369.tar.gz |
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
-rw-r--r-- | ChangeLog | 5 | ||||
-rw-r--r-- | lib/pstore.rb | 7 |
2 files changed, 9 insertions, 3 deletions
@@ -1,3 +1,8 @@ +Tue Jun 28 22:55:00 2016 Nobuyoshi Nakada <nobu@ruby-lang.org> + + * lib/pstore.rb (PStore::CHECKSUM_ALGO): extract the algorithm for + checksum, instead of qualified names for each times. + Tue Jun 28 22:29:36 2016 Nobuyoshi Nakada <nobu@ruby-lang.org> * bootstraptest/runner.rb: do not use safe navigation operator. 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) |