perf: F.detect: the extension's format scoring 1 returns at once (65x with a name), archive/br's trial-decode sniff runs last and only when it could still win; mpegts sniff finds sync bytes with string.find; inflate reuses its dynamic-table scratch buffers
This commit is contained in:
1 parent
11b7f89dab
commit
3320339507
3 files changed
+70
-25
No files matched your search
@@ -54,6 +54,9 @@ do
|
||||
FDISTS = Huffman.buildLsbMap(d, 0, 30, FDIST, DISTBITS, DMAP)
|
||||
end
|
||||
|
||||
-- scratch tables for dynamic blocks, shared by every call (raw never yields)
|
||||
local SLIT, SDIST, SCL, SLENS = bcreate(LITCAP * 4), bcreate(DISTCAP * 4), bcreate(CLCAP * 4), bcreate(320)
|
||||
|
||||
local Inflate = {}
|
||||
|
||||
local function grow(out: buffer, op: number, need: number): (buffer, number)
|
||||
@@ -75,9 +78,9 @@ function Inflate.raw(src: buffer, start: number, endpos: number, cap: number, ex
|
||||
end
|
||||
local pos = start
|
||||
local bitbuf, bitcnt, over = 0, 0, 0
|
||||
local lt, dt = bcreate(LITCAP * 4), bcreate(DISTCAP * 4) :: buffer
|
||||
local clt = bcreate(CLCAP * 4)
|
||||
local lens = bcreate(320)
|
||||
local lt, dt = SLIT, SDIST
|
||||
local clt = SCL
|
||||
local lens = SLENS
|
||||
local final = 0
|
||||
repeat
|
||||
-- block header (3 bits); also up to 14 bits of a dynamic header
|
||||
@@ -146,9 +149,7 @@ function Inflate.raw(src: buffer, start: number, endpos: number, cap: number, ex
|
||||
lt, dt = FLIT, FDIST
|
||||
lsub, dsub = FLITS, FDISTS
|
||||
elseif btype == 2 then
|
||||
if lt == FLIT then
|
||||
lt, dt = bcreate(LITCAP * 4), bcreate(DISTCAP * 4) :: buffer
|
||||
end
|
||||
lt, dt = SLIT, SDIST
|
||||
local hlit = band(bitbuf, 31) + 257
|
||||
local hdist = band(rshift(bitbuf, 5), 31) + 1
|
||||
local hclen = band(rshift(bitbuf, 10), 15) + 4
|
||||
|
||||
Reference in new issue
Block a user