mirror of
https://github.com/IfcOpenShell/IfcOpenShell.git
synced 2026-09-22 01:10:58 +00:00
ifcparse: keep unresolved references in the attribute slots
The parser could not resolve a #name when it read it, because the instance may be defined further down the file, so it left the slot empty and appended (owner, attribute, name) to a side table that a second pass walked. The table held one entry per reference for the whole read: 64 MB on a 58 MB model, the high-water mark of opening. Now the reference stays where the tokenizer put it: the attribute slot holds the instance_reference, or the reference_or_simple_type aggregate for a list (mixed with inline typed values or not), until every instance has been read, and resolve_instance_references() walks each instance's slots and swaps names for instances. Ordering is what the tokenizer produced; nothing is re-derived. A missing name becomes null in a scalar and is dropped from an aggregate, as before; the error keeps its offset. The three transient alternatives are appended to the attribute pack and to argument_type in lock step and are never visible once a file is loaded. Simple type instances read inline (IfcPropertySetDefinitionSet) have their own slots, so their references need no diversion. The table remains for the header entities and for streaming consumers of instance_streamer::references(), which leave resolve_references_in_place off. TXG 58 MB / 210_King 147 MB / OKgate22 231 MB, single thread: time unchanged (1.05 / 2.69 / 4.99 s), memory after the parse 287 -> 274, 698 -> 654, 1086 -> 1036 MB, peak 400 -> 365, 965 -> 871, 1471 -> 1347 MB. This commit was written by an AI coding tool and has not been verified by a human. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_013wcN7XquTfUi4vsKQ4KchL
This commit is contained in:
@@ -576,6 +576,14 @@ namespace ifcopenshell {
|
||||
const ifcopenshell::schema_definition* schema;
|
||||
|
||||
unresolved_references* references_to_resolve = nullptr;
|
||||
// When set, a reference read into an instance's attribute stays
|
||||
// in the attribute slot as the instance_reference (or the
|
||||
// reference_or_simple_type aggregate) the tokenizer produced,
|
||||
// instead of being copied into references_to_resolve, and
|
||||
// resolve_instance_references() replaces it with the instance
|
||||
// once every instance has been read. read_from_stream() turns it
|
||||
// on; streaming consumers of references() leave it off.
|
||||
bool resolve_references_in_place = false;
|
||||
|
||||
typedef std::map<const ifcopenshell::declaration*, std::vector<express::base>> entities_by_type;
|
||||
typedef std::unordered_map<uint32_t, shared_pointer_type> entity_instance_by_name_storage;
|
||||
@@ -650,6 +658,11 @@ namespace ifcopenshell {
|
||||
shared_pointer_type load(ifcopenshell::spf_lexer<Reader>* tokens, std::optional<size_t> entity_instance_name, const ifcopenshell::declaration* declaration, const ifcopenshell::entity* entity, int attribute_index = -1, bool coerce_attribute_count = true);
|
||||
template <typename Reader>
|
||||
void try_read_semicolon(ifcopenshell::spf_lexer<Reader>* tokens) const;
|
||||
// Replaces the names left in `data`'s attribute slots by in-place
|
||||
// reference storage with the instances they name; a name that is
|
||||
// missing or bypassed becomes null in a scalar and is dropped
|
||||
// from an aggregate.
|
||||
void resolve_instance_references(const shared_pointer_type& data, const std::vector<unsigned>& bypassed);
|
||||
|
||||
void register_inverse(unsigned referenced_id, const ifcopenshell::entity* from_entity, int instance_id, int attribute_index);
|
||||
void unregister_inverse(unsigned referenced_id, const ifcopenshell::entity* from_entity, const express::base& entity, int attribute_index);
|
||||
|
||||
Reference in New Issue
Block a user