Xml.free gives back a parsed tree's records and lists (never its strings) and the parser's cursor is freed; ludic.ui frees a template's XML once built, sel_parse's and ex_parse's readers, lss_rule's declarations holder, and px_cmp no longer makes a list of its operators per call

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Orkun ÇAKILKAYA 2026-09-29 00:11:40 +03:00
parent 3816d9924b
commit 7b20f305ff
8 changed files with 40 additions and 8 deletions

View file

@ -495,6 +495,7 @@ namespace Json {
}
namespace Xml {
alias parse(text) = xml_parse
alias free(node) = xml_free # the tree's records and lists; its strings are kept
alias tag(node) = xml_tag
alias text(node) = xml_text
alias attr(node, key) = xml_attr

View file

@ -322,8 +322,26 @@ function xml_parse(rt_xml_st: mut RtXmlState, s: pointer) -> Xml {
if p.i >= p.n { break }
if p.s[p.i] == '<' { # '<'
if xp_skip_misc(p) { } # prolog / comment / doctype
else { return xp_element(rt_xml_st, p) }
else {
let root = xp_element(rt_xml_st, p)
free(p)
return root
}
} else { p.i += 1 }
}
free(p)
return xml_new("")
}
# the tree's records and lists given back once a reader has built what it keeps from it; its
# strings (tags, text, names, values) are not, since what was built may hold them. Every element
# is in its parent's `mixed`, with the runs of text
function xml_free(n: Xml) -> void {
if n == null { return }
for i in 0 .. len(n.mixed) { xml_free(n.mixed[i]) }
free(n.akeys)
free(n.avals)
free(n.kids)
free(n.mixed)
free(n)
}