Replace tinyxml2 with pugixml
Parsing a 60 MB save drops from about 350 ms to 30 ms (a whole load from about
620 ms to 200). The reader keeps tinyxml2's rules for numbers and booleans
("%d"/"%f" on the leading text; a number or true/false), so every golden is
unchanged, and parse errors now give a line. SVG composing (pack and merge)
builds, clones and prints through pugixml. Tests check escaping by reading a
save back instead of comparing against tinyxml2's printer, and cut
SourceDocument from saves as text. pugixml is a submodule at v1.16; the About
window lists it, and simdjson, instead of tinyxml2.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
b69b0eaa1b
commit
201a7c7cfc
9 files changed
+242
-195
No files matched your search
+7
-11
@@ -8,8 +8,6 @@
|
||||
#include <fstream>
|
||||
#include <sstream>
|
||||
|
||||
#include <tinyxml2/tinyxml2.h>
|
||||
|
||||
#include "edit/edit.hpp"
|
||||
#include "model/json.hpp"
|
||||
#include "model/xml.hpp"
|
||||
@@ -79,16 +77,14 @@ namespace anm2ed::test
|
||||
return variants;
|
||||
}
|
||||
|
||||
// The outer document of a save with its SourceDocument removed: what the game reads.
|
||||
inline std::string game_document_get(const std::string& text)
|
||||
// The outer document of a save with its SourceDocument (the root's last child, on lines of its own) removed: what
|
||||
// the game reads.
|
||||
inline std::string game_document_get(std::string text)
|
||||
{
|
||||
tinyxml2::XMLDocument document{};
|
||||
document.Parse(text.c_str());
|
||||
if (auto source = document.RootElement()->FirstChildElement("SourceDocument"))
|
||||
document.RootElement()->DeleteChild(source);
|
||||
tinyxml2::XMLPrinter printer{};
|
||||
document.Print(&printer);
|
||||
return printer.CStr();
|
||||
constexpr std::string_view END = "</SourceDocument>";
|
||||
auto start = text.find("\n <SourceDocument");
|
||||
if (start != std::string::npos) text.erase(start, text.find(END, start) + END.size() - start);
|
||||
return text;
|
||||
}
|
||||
|
||||
// Save/reload properties every document must hold.
|
||||
|
||||
@@ -12,7 +12,7 @@ TEST_CASE("per-fixture invariants")
|
||||
}
|
||||
}
|
||||
|
||||
TEST_CASE("saved text is what tinyxml2 prints for the same document")
|
||||
TEST_CASE("saved text escapes what it holds, and reads back the same")
|
||||
{
|
||||
auto model = model_load(file_load(CORPUS_DIR / "11_unknown.anm2"));
|
||||
model.extras.children.emplace_back(
|
||||
@@ -21,11 +21,12 @@ TEST_CASE("saved text is what tinyxml2 prints for the same document")
|
||||
.text = "a & b > c 'd' \"e\"",
|
||||
.children = {{.tag = "Inner", .children = {{.tag = "Leaf", .attributes = {{"A", "1"}}}}}}});
|
||||
auto text = model::model_to_string(model);
|
||||
tinyxml2::XMLDocument document{};
|
||||
REQUIRE(document.Parse(text.c_str()) == tinyxml2::XML_SUCCESS);
|
||||
tinyxml2::XMLPrinter printer{};
|
||||
document.Print(&printer);
|
||||
CHECK(text == printer.CStr());
|
||||
CHECK(text.find("Quote=\"it's "x" & <y>\"") != std::string::npos);
|
||||
CHECK(text.find(">a & b > c 'd' \"e\"<") != std::string::npos);
|
||||
auto reloaded = model_load(text).extras.children;
|
||||
auto note = std::ranges::find(reloaded, std::string("Note"), [](const auto& child) { return child.second.tag; });
|
||||
REQUIRE(note != reloaded.end());
|
||||
CHECK(note->second == model.extras.children.back().second);
|
||||
}
|
||||
|
||||
TEST_CASE("purged default colors read back the same")
|
||||
|
||||
Reference in new issue
Block a user