perf: slice-by-8 MSB-first CRC-32 (Crc32.msb) for Ogg pages and bzip2 blocks; bzip2 checks each block's CRC over its output at once and moves long MTF shifts with table.move
This commit is contained in:
1 parent
2dac8b2a14
commit
5b4ee7f937
5 files changed
+56
-33
No files matched your search
@@ -8,11 +8,9 @@
|
||||
-- of a multiplexed file come first when every stream's first packet is written (with flush) before any other.
|
||||
-- Never throws: a bad argument returns false, Err.
|
||||
local Err = require("@rosetta/core/Err")
|
||||
local Page = require("@rosetta/containers/Ogg/Page")
|
||||
local Crc32 = require("@rosetta/core/Crc32")
|
||||
|
||||
local CRC = Page.CRC_TABLE
|
||||
local readu8, writeu8, writeu32, writei32 = buffer.readu8, buffer.writeu8, buffer.writeu32, buffer.writei32
|
||||
local bxor, lshift, rshift = bit32.bxor, bit32.lshift, bit32.rshift
|
||||
local writeu8, writeu32, writei32 = buffer.writeu8, buffer.writeu32, buffer.writei32
|
||||
|
||||
local Mux = {}
|
||||
Mux.__index = Mux
|
||||
@@ -63,11 +61,7 @@ end
|
||||
|
||||
-- the CRC of a page (the crc field written as zero)
|
||||
local function crc(b: buffer, n: number): number
|
||||
local c = 0
|
||||
for i = 0, n - 1 do
|
||||
c = bxor(lshift(c, 8), CRC[bxor(rshift(c, 24), readu8(b, i)) + 1])
|
||||
end
|
||||
return c
|
||||
return Crc32.msb(b, 0, n, 0)
|
||||
end
|
||||
|
||||
function Stream._flush(self: any, eos: boolean)
|
||||
|
||||
@@ -32,10 +32,7 @@ local CRC = Crc32.MSB_TABLE
|
||||
Page.CRC_TABLE = CRC
|
||||
|
||||
local function crcRange(b: buffer, from: number, to: number, crc: number): number
|
||||
for i = from, to - 1 do
|
||||
crc = bxor(lshift(crc, 8), CRC[bxor(rshift(crc, 24), readu8(b, i)) + 1])
|
||||
end
|
||||
return crc
|
||||
return Crc32.msb(b, from, to - from, crc)
|
||||
end
|
||||
|
||||
-- the Ogg CRC-32 of arbitrary data (the crc field is not zeroed)
|
||||
|
||||
Reference in new issue
Block a user