From 9b13dc8dd65090b6fa4206d77cc3d2416a057aad Mon Sep 17 00:00:00 2001 From: Thomas Krijnen Date: Wed, 22 Apr 2026 12:03:58 +0200 Subject: [PATCH] Get rid of parse context pool --- src/ifcparse/file.cpp | 10 +++---- src/ifcparse/parse.cpp | 9 +++---- src/ifcparse/storage.h | 61 ++---------------------------------------- 3 files changed, 10 insertions(+), 70 deletions(-) diff --git a/src/ifcparse/file.cpp b/src/ifcparse/file.cpp index fde73657b2..80ea1011fc 100644 --- a/src/ifcparse/file.cpp +++ b/src/ifcparse/file.cpp @@ -21,9 +21,9 @@ ifcopenshell::parse_context::~parse_context() { } ifcopenshell::parse_context& ifcopenshell::parse_context::push() { - auto child = pool_->make(); - tokens_.emplace_back(child); - return *child; + auto* pc = new parse_context; + tokens_.push_back(pc); + return *pc; } void ifcopenshell::parse_context::push(token t) { @@ -220,7 +220,7 @@ namespace { if constexpr (std::is_same_v, ifcopenshell::token>) { // @todo get aggregate of enumeration dispatch_token(instance_id, attribute_id, v, aggr && aggr->type_of_element()->as_named_type() ? aggr->type_of_element()->as_named_type()->declared_type() : nullptr, append_to_aggregate_storage); - } else if constexpr (std::is_same_v, ifcopenshell::parse_context_handle>) { + } else if constexpr (std::is_same_v, ifcopenshell::parse_context*>) { // nested list if constexpr (Depth < 3) { construct_(instance_id, attribute_id, *v, nullptr, append_to_aggregate_storage); @@ -307,7 +307,7 @@ std::shared_ptr ifcopenshell::parse_context::construct(ifcopenshe storage.set(index, v); } }); - } else if constexpr (std::is_same_v, ifcopenshell::parse_context_handle>) { + } else if constexpr (std::is_same_v, ifcopenshell::parse_context*>) { const auto *pt = param_type; if (pt) { while (pt->as_named_type() && pt->as_named_type()->declared_type()->as_type_declaration()) { diff --git a/src/ifcparse/parse.cpp b/src/ifcparse/parse.cpp index 89e0dc278c..8865068689 100644 --- a/src/ifcparse/parse.cpp +++ b/src/ifcparse/parse.cpp @@ -602,7 +602,7 @@ void ifcopenshell::impl::in_memory_file_storage::load(ifcopenshell::spf_lexerschema())->declaration_by_name(next.as_string()); - parse_context ps(&context_pool_); + parse_context ps; tokens->next(); // The only case we know where a defined type contains entity // instance references is IfcPropertySetDefinitionSet. For @@ -1387,11 +1387,10 @@ std::shared_ptr read_header_entity( spf_lexer& lexer, ifcopenshell::unresolved_references& references_to_resolve, const ifcopenshell::entity& decl) { - parse_context pc(&storage.context_pool_); + parse_context pc; lexer.next(); storage.load(&lexer, std::nullopt, nullptr, pc, -1); auto result = pc.construct(file, std::nullopt, references_to_resolve, &decl, decl.attribute_count(), -1); - storage.context_pool_.reset(); return result; } @@ -1436,7 +1435,6 @@ bool try_parse_header( parse_header(header, storage, lexer, references_to_resolve); return true; } catch (const std::exception& e) { - storage.context_pool_.reset(); logger::error(e); return false; } @@ -1697,7 +1695,7 @@ std::optionalnext(); try { storage_.load(lexer_.get(), current_id, entity_type->as_entity(), ps, -1); @@ -1714,7 +1712,6 @@ std::optional() const; - parse_context& operator*() const; - explicit operator bool() const { return pool != nullptr; } - }; - struct IFC_PARSE_API parse_context { std::vector< std::variant< express::Base, token, - parse_context_handle + parse_context* >> tokens_; - void reset() { - tokens_.clear(); - } - - parse_context_pool* pool_; - - parse_context(parse_context_pool* pool) : pool_(pool) { - tokens_.reserve(16); - }; + parse_context() {} ~parse_context(); parse_context(const parse_context& other) = delete; @@ -250,44 +229,8 @@ namespace ifcopenshell { std::shared_ptr construct(ifcopenshell::file* owner_file, std::optional instance_name, unresolved_references& references_to_resolve, const ifcopenshell::declaration* declaration, std::optional expected_size, int resolve_reference_index, bool coerce_attribute_count = true); }; - struct IFC_PARSE_API parse_context_pool { - // parse_context::push() stores child handles on the current context after - // requesting a new pool slot. The pool therefore needs stable addresses - // for existing contexts while it grows. - std::deque nodes_; - uint32_t used_ = 0; - - void reset() { used_ = 0; } - - parse_context_handle make() { - if (used_ == nodes_.size()) { - nodes_.emplace_back(this); - } - auto idx = used_++; - nodes_[idx].reset(); - return {this, idx}; - } - - parse_context& get(uint32_t index) { - return nodes_[index]; - } - }; - - inline parse_context& parse_context_handle::get() const { - return pool->get(index); - } - - inline parse_context* parse_context_handle::operator->() const { - return &pool->get(index); - } - - inline parse_context& parse_context_handle::operator*() const { - return pool->get(index); - } - namespace impl { struct IFC_PARSE_API in_memory_file_storage { - ifcopenshell::parse_context_pool context_pool_; std::vector> read_simple_type_instances; std::vector> steal_instances() {