mirror of
https://github.com/qelectrotech/qelectrotech-source-mirror.git
synced 2026-07-30 07:44:13 +02:00
ElementFactory: read link_type from the cached QDom, drop pugixml pass
createElement() ran a full pugixml parse of the element definition for every instance, only to read the link_type attribute for the subclass dispatch - on a big example project (191 instances) 49 ms of the load, measured with temporary instrumentation. The QDom definition is already cached and the ctor uses it anyway; reading the attribute there costs ~17 ms in total, so the net win is ~30 ms - within run-to-run noise end-to-end, but it removes an entire redundant parser pass per element. Behavior unchanged: an absent and an empty link_type both fell through to SimpleElement before and still do. (cherry picked from commit d63275971f558c8ac59f35bf4d13d7e424682342)
This commit is contained in:
@@ -42,10 +42,14 @@ Element * ElementFactory::createElement(const ElementsLocation &location, QGraph
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
auto doc = location.pugiXml();
|
||||
if (doc.document_element().attribute("link_type"))
|
||||
//Read the link_type from the (cached) QDom definition instead of
|
||||
//running a second, pugixml parse of the same definition: this
|
||||
//dispatch runs once per element instance on project load, and the
|
||||
//pugixml detour was ~4 % of the whole load time of a big project.
|
||||
const QString link_type =
|
||||
location.xml().attribute(QStringLiteral("link_type"));
|
||||
if (!link_type.isEmpty())
|
||||
{
|
||||
QString link_type(doc.document_element().attribute("link_type").as_string());
|
||||
if (link_type == QLatin1String("next_report") || link_type == QLatin1String("previous_report"))
|
||||
return (new ReportElement(location, link_type, qgi, state));
|
||||
if (link_type == QLatin1String("master"))
|
||||
|
||||
Reference in New Issue
Block a user