Skip to content

Commit 5b4f6a9

Browse files
authored
Optimize check_checksum_field (#184)
1 parent 8e00c03 commit 5b4f6a9

1 file changed

Lines changed: 11 additions & 2 deletions

File tree

src/extract.jl

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -628,9 +628,18 @@ end
628628

629629
function check_checksum_field(buf::AbstractVector{UInt8})
630630
chksum = read_header_int(buf, :chksum)
631-
actual = let r = index_range(:chksum)
632-
sum(i in r ? UInt8(' ') : buf[i] for i = 1:512)
631+
r = index_range(:chksum)
632+
r_first, r_last = first(r), last(r)
633+
634+
actual = zero(UInt32)
635+
for i in 1:(r_first-1)
636+
actual += buf[i]
637+
end
638+
actual += UInt32(' ') * (r_last - r_first + 1)
639+
for i in (r_last+1):512
640+
actual += buf[i]
633641
end
642+
634643
chksum == actual && return
635644
header_error(buf, "incorrect header checksum = $chksum; should be $actual")
636645
end

0 commit comments

Comments
 (0)