ws-cleanup: shared helpers instead of copies (CRCs, codec arguments, utf8char, keyLess / isArray)
A sweep for duplicated function bodies, CRC tables and base64 across src/Formats: - core/Crc32.msb / MSB_TABLE: the MSB-first 0x04C11DB7 CRC-32 that containers/Ogg (Page + Mux), containers/MpegTs and codecs/Bzip2 each built (test vectors CRC-32/MPEG-2 and /BZIP2 in tests/core/bytes). - audio/flac/Encode uses audio/flac/Frame's CRC-8 / CRC-16 tables (Frame.crc8 added) instead of its own copy. - core/Bytes.toBuffer / Bytes.span: the (buffer | string, offset, length) argument checking codecs/Deflate, codecs/Lzma and codecs/Brotli each carried. - codecs/Text.utf8char: one copy instead of four (codecs/Json, codecs/Xml, data/yaml, data/toml). - Types.keyLess / Types.isArray (small additions to Types, backward compatible): data/msgpack, data/cbor and data/yaml/Emit had identical copies. - playlist/pls: dead copies of m3u's attributes / extinf removed. Left on purpose: per-codec bit readers / writers in hot loops (STYLE.md: inner loops keep their own bit buffers), same-folder helpers (Alac signExtend, Vorbis ilog), Zip's DOS-date civil() (a different epoch helper).
This commit is contained in:
1 parent
7169f2cc2c
commit
f784b4eb9b
22 files changed
+152
-311
No files matched your search
@@ -120,34 +120,9 @@ local function str(s: string, ind: string, key: boolean): string
|
||||
return dquote(s)
|
||||
end
|
||||
|
||||
local function isArray(t: { [any]: any }): boolean
|
||||
if Types.isObject(t) then
|
||||
return false
|
||||
end
|
||||
local n = #t
|
||||
if n == 0 then
|
||||
return next(t) == nil
|
||||
end
|
||||
if next(t, n) ~= nil then
|
||||
return false
|
||||
end
|
||||
local c = 0
|
||||
for _ in next, t do
|
||||
c += 1
|
||||
end
|
||||
return c == n
|
||||
end
|
||||
local isArray = Types.isArray
|
||||
|
||||
local function keyLess(a: any, b: any): boolean
|
||||
local ta, tb = type(a), type(b)
|
||||
if ta ~= tb then
|
||||
return ta < tb
|
||||
end
|
||||
if ta == "number" or ta == "string" then
|
||||
return a < b
|
||||
end
|
||||
return tostring(a) < tostring(b)
|
||||
end
|
||||
local keyLess = Types.keyLess
|
||||
|
||||
type St = { out: { string }, step: number, sort: boolean, null: any, refs: { [any]: number }, anchors: { [any]: string }, nextId: number, err: string? }
|
||||
|
||||
|
||||
@@ -6,6 +6,7 @@
|
||||
-- opts.tags = "ignore"), %YAML / %TAG directives, multi-document streams, comments. Scalars resolve with the core
|
||||
-- schema. Not supported: complex keys ("? "), collections as keys, recursive aliases, merge keys "<<" (kept as a
|
||||
-- normal key). Internally raises { yamlErr } tables caught by run(); never throws past it.
|
||||
local Text = require("@formats/codecs/Text")
|
||||
local Types = require("@formats/Types")
|
||||
local Base64 = require("@formats/core/Base64")
|
||||
|
||||
@@ -116,16 +117,7 @@ local function endOfLine(s: string, p: number): boolean
|
||||
return c == nil or c == 10 or (c == 35 and q > p)
|
||||
end
|
||||
|
||||
local function utf8char(c: number): string
|
||||
if c < 0x80 then
|
||||
return char(c)
|
||||
elseif c < 0x800 then
|
||||
return char(0xC0 + c // 64, 0x80 + c % 64)
|
||||
elseif c < 0x10000 then
|
||||
return char(0xE0 + c // 4096, 0x80 + (c // 64) % 64, 0x80 + c % 64)
|
||||
end
|
||||
return char(0xF0 + c // 262144, 0x80 + (c // 4096) % 64, 0x80 + (c // 64) % 64, 0x80 + c % 64)
|
||||
end
|
||||
local utf8char = Text.utf8char
|
||||
|
||||
-- ------------------------------------------------------------------------------------------------ resolution
|
||||
-- the core schema: a plain scalar's value
|
||||
|
||||
@@ -20,7 +20,7 @@ local Yaml = {
|
||||
category = "data",
|
||||
extensions = { "yaml", "yml" },
|
||||
mime = { "application/yaml", "application/x-yaml", "text/yaml" },
|
||||
deps = { "core/Err", "core/Bytes", "Types", "core/Base64" },
|
||||
deps = { "core/Err", "core/Bytes", "Types", "core/Base64", "codecs/Text" },
|
||||
caps = { decode = true, encode = true, ordered = true, multiDocument = true, anchors = true },
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user