Skip to content

Commit

Permalink
[rubygems/rubygems] Improve TarHeader#calculate_checksum
Browse files Browse the repository at this point in the history
String#unpack("C*") is equivalent to String#bytes and Array#inject {|a,b| a + b } is equivalent to Array#sum.
This is a minor enhancement in terms of speed and readability.
  • Loading branch information
Maumagnaguagno authored and matzbot committed Mar 16, 2023
1 parent cae4342 commit 364364c
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion lib/rubygems/package/tar_header.rb
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@ def update_checksum
private

def calculate_checksum(header)
header.unpack("C*").inject {|a, b| a + b }
header.bytes.sum
end

def header(checksum = @checksum)
Expand Down

0 comments on commit 364364c

Please sign in to comment.