Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 13 additions & 5 deletions src/internal/gzip_internal/crc32.mbt
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,18 @@ let crc32_table : FixedArray[UInt] = FixedArray::makei(256, i => {

///|
fn crc32_update(current : UInt, chunk : BytesView) -> UInt {
for byte in chunk; crc = current {
let index = ((crc ^ byte.to_uint()) & 0xffU).reinterpret_as_int()
continue crc32_table[index] ^ (crc >> 8)
} nobreak {
crc
// Pull out the backing Bytes + start offset once and index that
// directly. `for byte in chunk` desugars through BytesView::iter +
// Iter::next (15-16% in a gzip_roundtrip profile), and even
// `chunk[i]` (= BytesView::at) is a non-inlined function call
// (6.88% before this change). Indexing the raw Bytes is intrinsic.
let mut crc = current
let bytes = chunk.data()
let start = chunk.start_offset()
let len = chunk.length()
for i in 0..<len {
let index = ((crc ^ bytes[start + i].to_uint()) & 0xffU).reinterpret_as_int()
crc = crc32_table[index] ^ (crc >> 8)
}
crc
}
Loading