Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 10 additions & 3 deletions inkcpp_compiler/json_compiler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,14 @@ namespace ink::compiler::internal
using nlohmann::json;
using std::vector;

typedef std::tuple<json, std::string> defer_entry;
/* Holds a pointer, not the container itself. Storing the json by value here
* deep-copied every named child's whole subtree, and because compile_container
* then recursed into that copy and deferred *its* children the same way, a
* container nested d levels deep was copied d times over. The source document
* outlives the entire compile (it is the caller's json, reached by reference
* through compile() -> compile_container() -> handle_container_metadata()), so
* borrowing is safe. */
typedef std::tuple<const json*, std::string> defer_entry;

json_compiler::json_compiler()
: _emitter(nullptr)
Expand Down Expand Up @@ -117,7 +124,7 @@ void json_compiler::handle_container_metadata(const json& meta, container_meta&
// Child container
else {
// Add to deferred compilation list
data.deferred.push_back(std::make_tuple(meta_iter.value(), meta_iter.key()));
data.deferred.push_back(std::make_tuple(&meta_iter.value(), meta_iter.key()));
}
}
} else if (is_knot) {
Expand Down Expand Up @@ -230,7 +237,7 @@ void json_compiler::compile_container(
using std::get;

// Add to named child list
compile_container(get<0>(t), -1, depth + 1, get<1>(t));
compile_container(*get<0>(t), -1, depth + 1, get<1>(t));

// Need a divert here
uint32_t pos = _emitter->fallthrough_divert();
Expand Down