perf: rbxmx / XML decode 2.5x: Types.object keeps the key order in the object's own metatable (no global weak map insert), XML fast paths for plain attributes / text / end tags, utf8.len validation, rbxmx components read in order
This commit is contained in:
1 parent
158fa3d3f0
commit
0ec772ee30
5 files changed
+153
-28
No files matched your search
@@ -81,6 +81,10 @@ local function num(s: string?): number
|
||||
if s == nil then
|
||||
return 0
|
||||
end
|
||||
local v = tonumber(s)
|
||||
if v then
|
||||
return v
|
||||
end
|
||||
local t = string.lower((string.gsub(s, "^%s+", "")))
|
||||
t = string.gsub(t, "%s+$", "")
|
||||
if t == "inf" or t == "+inf" or t == "infinity" then
|
||||
@@ -100,8 +104,27 @@ end
|
||||
local function comps(node: Xml.Node?, names: { string }): { number }
|
||||
local out = table.create(#names, 0)
|
||||
if node then
|
||||
-- the children in order, element i usually named names[i]
|
||||
local kids = node.children
|
||||
local k = 1
|
||||
for i, n in names do
|
||||
out[i] = num(childText(node, n))
|
||||
local c = nil
|
||||
while k <= #kids do
|
||||
local ch = kids[k]
|
||||
if type(ch) == "table" then
|
||||
if ch.name == n then
|
||||
c = ch
|
||||
end
|
||||
break
|
||||
end
|
||||
k += 1
|
||||
end
|
||||
if c then
|
||||
k += 1
|
||||
else
|
||||
c = Xml.child(node, n)
|
||||
end
|
||||
out[i] = num(if c then Xml.text(c) else nil)
|
||||
end
|
||||
end
|
||||
return out
|
||||
@@ -117,10 +140,10 @@ end
|
||||
local CF_NAMES = { "X", "Y", "Z", "R00", "R01", "R02", "R10", "R11", "R12", "R20", "R21", "R22" }
|
||||
local PHYS_NAMES = { "Density", "Friction", "Elasticity", "FrictionWeight", "ElasticityWeight" }
|
||||
|
||||
local function readRaw(node: Xml.Node, shared: { [string]: string }, key: string): (string, any)
|
||||
local function readRaw(node: Xml.Node, shared: { [string]: string }, cls: string, pname: string): (string, any)
|
||||
local tag = node.name
|
||||
local scalar = SCALAR_TAGS[tag]
|
||||
if tag == "int" and BRICKCOLOR[key] then
|
||||
if tag == "int" and BRICKCOLOR[cls .. "." .. pname] then
|
||||
scalar = "BrickColor"
|
||||
end
|
||||
if scalar then
|
||||
@@ -264,8 +287,8 @@ local function round32(v: any, which: any): any
|
||||
end
|
||||
return v
|
||||
end
|
||||
local function readValue(node: Xml.Node, shared: { [string]: string }, key: string): (string, any)
|
||||
local t, v = readRaw(node, shared, key)
|
||||
local function readValue(node: Xml.Node, shared: { [string]: string }, cls: string, pname: string): (string, any)
|
||||
local t, v = readRaw(node, shared, cls, pname)
|
||||
local which = F32[t]
|
||||
if which then
|
||||
v = round32(v, which)
|
||||
@@ -316,7 +339,7 @@ function Rbxmx.decode(r: Bytes.Reader, opts: DecodeOptions?): (Rbx.Tree?, Err.Er
|
||||
if type(pnode) == "table" and string.sub(pnode.name, 1, 1) ~= "#" then
|
||||
local pname = pnode.attrs.name
|
||||
if type(pname) == "string" then
|
||||
local t, v = readValue(pnode, shared, cls .. "." .. pname)
|
||||
local t, v = readValue(pnode, shared, cls, pname)
|
||||
if pname == "Name" and (t == "String" or t == "ProtectedString") then
|
||||
inst.name = v
|
||||
else
|
||||
|
||||
Reference in new issue
Block a user