Skip to content

Commit d6891c9

Browse files
committed
Extra formatting and documentation.
1 parent a0d7fda commit d6891c9

1 file changed

Lines changed: 16 additions & 7 deletions

File tree

arch/INFLATE.LUA

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,10 @@ function inflate(r, w, z)
4242
---@return number The bits that where read
4343
function rb(n)
4444
nb(n)
45+
46+
-- v = extracted bit value
4547
local v = bb & ((1 << n) - 1)
48+
4649
bb, bc = (bb >> n), bc - n
4750
return v
4851
end
@@ -133,7 +136,10 @@ function inflate(r, w, z)
133136
-- l = len
134137
for l = 1, h.max do
135138
c = c | (rb(1) << (l - 1))
139+
140+
-- e = entry
136141
local e = h.tab[c & ((1 << l) - 1)]
142+
137143
if e and e.len == l then return e.sym end
138144
end
139145

@@ -152,7 +158,8 @@ function inflate(r, w, z)
152158
-- hi = higher bits of 16-bit value
153159
-- l = length of value
154160
local lo, hi, l
155-
bb, bc = 0, 0 -- align (disregard remaining bits)
161+
162+
bb, bc = 0, 0 -- align and disregard remaining bits
156163
lo, hi = rb(8), rb(8) -- read length
157164
l = lo + hi * 256 -- calculate length
158165
lo, hi = rb(8), rb(8) -- read n-length
@@ -194,19 +201,21 @@ function inflate(r, w, z)
194201

195202
while #le < hl + hd do
196203

197-
-- s = sym
198-
local s = rh(ch)
204+
-- s = symbol
205+
-- x = repeat count
206+
-- l = code length
207+
local s, x, l = rh(ch)
199208

200209
if s <= 15 then
201210
le[#le + 1] = s
202211
elseif s == 16 then
203-
local x, l = rb(2) + 3, le[#le]
212+
x, l = rb(2) + 3, le[#le]
204213
for _ = 1, x do le[#le + 1] = l end
205214
elseif s == 17 then
206-
local x = rb(3) + 3
215+
x = rb(3) + 3
207216
for _ = 1, x do le[#le + 1] = 0 end
208217
elseif s == 18 then
209-
local x = rb(7) + 11
218+
x = rb(7) + 11
210219
for _ = 1, x do le[#le + 1] = 0 end
211220
end
212221
end
@@ -225,7 +234,7 @@ function inflate(r, w, z)
225234

226235
while true do
227236

228-
-- s = sym
237+
-- s = symbol
229238
local s = rh(h)
230239

231240
if s < 256 then

0 commit comments

Comments
 (0)