ruby-changes:43453
From: nobu <ko1@a...>
Date: Tue, 28 Jun 2016 22:55:07 +0900 (JST)
Subject: [ruby-changes:43453] nobu:r55527 (trunk): PStoRe: :CHECKSUM_ALGO
nobu 2016-06-28 22:55:02 +0900 (Tue, 28 Jun 2016) New Revision: 55527 https://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=55527 Log: PStore::CHECKSUM_ALGO * lib/pstore.rb (PStore::CHECKSUM_ALGO): extract the algorithm for checksum, instead of qualified names for each times. Modified files: trunk/ChangeLog trunk/lib/pstore.rb Index: ChangeLog =================================================================== --- ChangeLog (revision 55526) +++ ChangeLog (revision 55527) @@ -1,3 +1,8 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1 +Tue Jun 28 22:55:00 2016 Nobuyoshi Nakada <nobu@r...> + + * 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@r...> * bootstraptest/runner.rb: do not use safe navigation operator. Index: lib/pstore.rb =================================================================== --- lib/pstore.rb (revision 55526) +++ lib/pstore.rb (revision 55527) @@ -352,9 +352,10 @@ class PStore https://github.com/ruby/ruby/blob/trunk/lib/pstore.rb#L352 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 https://github.com/ruby/ruby/blob/trunk/lib/pstore.rb#L410 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 https://github.com/ruby/ruby/blob/trunk/lib/pstore.rb#L430 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) -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/