perf: XML encode (name cache, escape fast path, indent cache, no key list for attribute-less elements), Types.object shares one empty key list until set, rbxm column type check
This commit is contained in:
1 parent
0ec772ee30
commit
7947dd7f3b
3 files changed
+63
-19
No files matched your search
+23
-7
@@ -665,9 +665,10 @@ local function orderOf(v: any): { any }?
|
||||
end
|
||||
return objectMeta[v]
|
||||
end
|
||||
local NOKEYS = table.freeze({})
|
||||
function Types.object(t: { [any]: any }?, keys: { any }?): { [any]: any }
|
||||
local o: { [any]: any } = t or {}
|
||||
local k = keys or {}
|
||||
local k = keys or NOKEYS
|
||||
local mt = getmetatable(o)
|
||||
if mt == nil or (type(mt) == "table" and rawget(mt, "__keys") ~= nil) then
|
||||
setmetatable(o, { __object = true, __keys = k })
|
||||
@@ -682,7 +683,16 @@ end
|
||||
function Types.set(o: { [any]: any }, k: any, v: any)
|
||||
local order = orderOf(o)
|
||||
if order and o[k] == nil and v ~= nil then
|
||||
table.insert(order, k)
|
||||
if order == NOKEYS then
|
||||
local mt = getmetatable(o)
|
||||
if type(mt) == "table" and rawget(mt, "__keys") == NOKEYS then
|
||||
mt.__keys = { k }
|
||||
else
|
||||
objectMeta[o] = { k }
|
||||
end
|
||||
else
|
||||
table.insert(order, k)
|
||||
end
|
||||
end
|
||||
o[k] = v
|
||||
end
|
||||
@@ -718,23 +728,29 @@ end
|
||||
function Types.keys(t: { [any]: any }): { any }
|
||||
local order = orderOf(t)
|
||||
local out, seen = {}, {}
|
||||
local n = 0
|
||||
if order then
|
||||
for _, k in order do
|
||||
if t[k] ~= nil and not seen[k] then
|
||||
seen[k] = true
|
||||
table.insert(out, k)
|
||||
n += 1
|
||||
out[n] = k
|
||||
end
|
||||
end
|
||||
end
|
||||
local rest = {}
|
||||
local rest: { any }? = nil
|
||||
for k in next, t do
|
||||
if not seen[k] then
|
||||
table.insert(rest, k)
|
||||
if rest then
|
||||
table.insert(rest, k)
|
||||
else
|
||||
rest = { k }
|
||||
end
|
||||
end
|
||||
end
|
||||
if #rest > 0 then
|
||||
if rest then
|
||||
table.sort(rest, keyLess)
|
||||
table.move(rest, 1, #rest, #out + 1, out)
|
||||
table.move(rest, 1, #rest, n + 1, out)
|
||||
end
|
||||
return out
|
||||
end
|
||||
|
||||
Reference in new issue
Block a user