Skip to content

Commit 5402259

Browse files
Add extra Digest.update overloads for Bytes (#15736)
Ensures that `#to_slice` does indeed return a `Slice(UInt8)`
1 parent 505ebed commit 5402259

File tree

2 files changed

+10
-4
lines changed

2 files changed

+10
-4
lines changed

src/digest/adler32.cr

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,11 @@ class Digest::Adler32 < ::Digest
2222
end
2323

2424
def self.update(data, adler32 : UInt32) : UInt32
25-
slice = data.to_slice
26-
LibZ.adler32(adler32, slice, slice.size).to_u32
25+
update data.to_slice, adler32
26+
end
27+
28+
def self.update(data : Bytes, adler32 : UInt32) : UInt32
29+
LibZ.adler32(adler32, data, data.size).to_u32
2730
end
2831

2932
def self.combine(adler1 : UInt32, adler2 : UInt32, len) : UInt32

src/digest/crc32.cr

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,11 @@ class Digest::CRC32 < ::Digest
2222
end
2323

2424
def self.update(data, crc32 : UInt32) : UInt32
25-
slice = data.to_slice
26-
LibZ.crc32(crc32, slice, slice.size).to_u32
25+
update data.to_slice, crc32
26+
end
27+
28+
def self.update(data : Bytes, crc32 : UInt32) : UInt32
29+
LibZ.crc32(crc32, data, data.size).to_u32
2730
end
2831

2932
def self.combine(crc1 : UInt32, crc2 : UInt32, len) : UInt32

0 commit comments

Comments
 (0)