mirror of
https://github.com/qelectrotech/qelectrotech-source-mirror.git
synced 2026-07-31 16:44:14 +02:00
Merge pull request #570 from DieterMayerOSS/pr/xmlcollection-linear-lookup
Fix the Qt6 load-time regression: linear child lookup in XmlElementCollection
This commit is contained in:
@@ -186,23 +186,22 @@ QDomElement XmlElementCollection::child(const QDomElement &parent_element,
|
|||||||
if (parent_element.ownerDocument() != m_dom_document)
|
if (parent_element.ownerDocument() != m_dom_document)
|
||||||
return QDomElement();
|
return QDomElement();
|
||||||
|
|
||||||
//Get all childs element of parent_element
|
/* Walk the siblings directly instead of the previous
|
||||||
QDomNodeList child_list = parent_element.childNodes();
|
* childNodes()+item(i) double pass: QDomNodeList::item(i) restarts
|
||||||
QString tag_name(child_name.endsWith(".elmt")? "element" : "category");
|
* from the first child every call, which made this loop quadratic
|
||||||
QList <QDomElement> found_dom_element;
|
* in the number of children. This lookup runs several times per
|
||||||
for (int i=0 ; i<child_list.length() ; i++)
|
* element instance while loading a project, on the "import"
|
||||||
|
* category that holds every embedded definition. */
|
||||||
|
const QString tag_name = child_name.endsWith(QLatin1String(".elmt"))
|
||||||
|
? QStringLiteral("element") : QStringLiteral("category");
|
||||||
|
for (QDomElement child_element = parent_element.firstChildElement(tag_name) ;
|
||||||
|
!child_element.isNull() ;
|
||||||
|
child_element = child_element.nextSiblingElement(tag_name))
|
||||||
{
|
{
|
||||||
QDomElement child_element = child_list.item(i).toElement();
|
if (child_element.attribute(QStringLiteral("name")) == child_name)
|
||||||
if (child_element.tagName() == tag_name)
|
return child_element;
|
||||||
found_dom_element << child_element;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (found_dom_element.isEmpty()) return QDomElement();
|
|
||||||
|
|
||||||
foreach (QDomElement elmt, found_dom_element)
|
|
||||||
if (elmt.attribute("name") == child_name)
|
|
||||||
return elmt;
|
|
||||||
|
|
||||||
return QDomElement();
|
return QDomElement();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user