Use QStringLiteral and QLatin1String.

According to the Qt documentation
(https://doc.qt.io/qt-5/qstring.html#QStringLiteral)
(https://woboq.com/blog/qstringliteral.html), use QStringLiteral and
QLatin1String is better on some conditions (faster).
This commit change the code related to the loading of a project (in
qetproject class), let see if loading time is improved.
This commit is contained in:
joshua
2021-03-30 19:59:14 +02:00
parent 6602c65679
commit a4ca872158

View File

@@ -159,7 +159,7 @@ void QETProject::init()
writeBackup(); writeBackup();
QSettings settings; QSettings settings;
int autosave_interval = settings.value("diagrameditor/autosave-interval", 0).toInt(); int autosave_interval = settings.value(QStringLiteral("diagrameditor/autosave-interval"), 0).toInt();
if(autosave_interval > 0) if(autosave_interval > 0)
{ {
int ms = autosave_interval*60*1000; int ms = autosave_interval*60*1000;
@@ -1280,13 +1280,13 @@ void QETProject::readProjectXml(QDomDocument &xml_project)
m_state = ProjectParsingRunning; m_state = ProjectParsingRunning;
//The roots of the xml document must be a "project" element //The roots of the xml document must be a "project" element
if (root_elmt.tagName() == "project") if (root_elmt.tagName() == QLatin1String("project"))
{ {
//Normal opening mode //Normal opening mode
if (root_elmt.hasAttribute("version")) if (root_elmt.hasAttribute(QStringLiteral("version")))
{ {
bool conv_ok; bool conv_ok;
m_project_qet_version = root_elmt.attribute("version").toDouble(&conv_ok); m_project_qet_version = root_elmt.attribute(QStringLiteral("version")).toDouble(&conv_ok);
#if TODO_LIST #if TODO_LIST
#pragma message("@TODO use of version convert") #pragma message("@TODO use of version convert")
#endif #endif
@@ -1312,7 +1312,7 @@ void QETProject::readProjectXml(QDomDocument &xml_project)
} }
} }
} }
setTitle(root_elmt.attribute("title")); setTitle(root_elmt.attribute(QStringLiteral("title")));
} }
else else
{ {
@@ -1362,7 +1362,7 @@ void QETProject::readDiagramsXml(QDomDocument &xml_project)
} }
//Search the diagrams in the project //Search the diagrams in the project
QDomNodeList diagram_nodes = xml_project.elementsByTagName("diagram"); QDomNodeList diagram_nodes = xml_project.elementsByTagName(QStringLiteral("diagram"));
if(dlgWaiting) if(dlgWaiting)
dlgWaiting->setProgressBarRange(0, diagram_nodes.length()*3); dlgWaiting->setProgressBarRange(0, diagram_nodes.length()*3);
@@ -1381,7 +1381,7 @@ void QETProject::readDiagramsXml(QDomDocument &xml_project)
int diagram_order = -1; int diagram_order = -1;
if (!QET::attributeIsAnInteger(diagram_xml_element, if (!QET::attributeIsAnInteger(diagram_xml_element,
"order", QStringLiteral("order"),
&diagram_order)) &diagram_order))
diagram_order = 500000; diagram_order = 500000;
@@ -1424,7 +1424,7 @@ void QETProject::readDiagramsXml(QDomDocument &xml_project)
void QETProject::readElementsCollectionXml(QDomDocument &xml_project) void QETProject::readElementsCollectionXml(QDomDocument &xml_project)
{ {
//Get the embedded elements collection of the project //Get the embedded elements collection of the project
QDomNodeList collection_roots = xml_project.elementsByTagName("collection"); QDomNodeList collection_roots = xml_project.elementsByTagName(QStringLiteral("collection"));
QDomElement collection_root; QDomElement collection_root;
if (!collection_roots.isEmpty()) if (!collection_roots.isEmpty())
@@ -1449,8 +1449,8 @@ void QETProject::readElementsCollectionXml(QDomDocument &xml_project)
*/ */
void QETProject::readProjectPropertiesXml(QDomDocument &xml_project) void QETProject::readProjectPropertiesXml(QDomDocument &xml_project)
{ {
foreach (QDomElement e, QET::findInDomElement(xml_project.documentElement(), "properties")) for (auto dom_elmt : QET::findInDomElement(xml_project.documentElement(), QStringLiteral("properties")))
m_project_properties.fromXml(e); m_project_properties.fromXml(dom_elmt);
} }
/** /**
@@ -1462,7 +1462,7 @@ void QETProject::readProjectPropertiesXml(QDomDocument &xml_project)
void QETProject::readDefaultPropertiesXml(QDomDocument &xml_project) void QETProject::readDefaultPropertiesXml(QDomDocument &xml_project)
{ {
// Find xml element where is stored properties for new diagram // Find xml element where is stored properties for new diagram
QDomNodeList newdiagrams_nodes = xml_project.elementsByTagName("newdiagrams"); QDomNodeList newdiagrams_nodes = xml_project.elementsByTagName(QStringLiteral("newdiagrams"));
if (newdiagrams_nodes.isEmpty()) return; if (newdiagrams_nodes.isEmpty()) return;
QDomElement newdiagrams_elmt = newdiagrams_nodes.at(0).toElement(); QDomElement newdiagrams_elmt = newdiagrams_nodes.at(0).toElement();
@@ -1482,21 +1482,21 @@ void QETProject::readDefaultPropertiesXml(QDomDocument &xml_project)
QDomElement child_elmt = child.toElement(); QDomElement child_elmt = child.toElement();
if (child_elmt.isNull()) continue; if (child_elmt.isNull()) continue;
if (child_elmt.tagName() == "border") if (child_elmt.tagName() == QLatin1String("border"))
border_elmt = child_elmt; border_elmt = child_elmt;
else if (child_elmt.tagName() == "inset") else if (child_elmt.tagName() == QLatin1String("inset"))
titleblock_elmt = child_elmt; titleblock_elmt = child_elmt;
else if (child_elmt.tagName() == "conductors") else if (child_elmt.tagName() == QLatin1String("conductors"))
conductors_elmt = child_elmt; conductors_elmt = child_elmt;
else if (child_elmt.tagName() == "report") else if (child_elmt.tagName() == QLatin1String("report"))
report_elmt = child_elmt; report_elmt = child_elmt;
else if (child_elmt.tagName() == "xrefs") else if (child_elmt.tagName() == QLatin1String("xrefs"))
xref_elmt = child_elmt; xref_elmt = child_elmt;
else if (child_elmt.tagName() == "conductors_autonums") else if (child_elmt.tagName() == QLatin1String("conductors_autonums"))
conds_autonums = child_elmt; conds_autonums = child_elmt;
else if (child_elmt.tagName()== "folio_autonums") else if (child_elmt.tagName()== QLatin1String("folio_autonums"))
folio_autonums = child_elmt; folio_autonums = child_elmt;
else if (child_elmt.tagName()== "element_autonums") else if (child_elmt.tagName()== QLatin1String("element_autonums"))
element_autonums = child_elmt; element_autonums = child_elmt;
} }
@@ -1504,21 +1504,21 @@ void QETProject::readDefaultPropertiesXml(QDomDocument &xml_project)
if (!border_elmt.isNull()) default_border_properties_.fromXml(border_elmt); if (!border_elmt.isNull()) default_border_properties_.fromXml(border_elmt);
if (!titleblock_elmt.isNull()) default_titleblock_properties_.fromXml(titleblock_elmt); if (!titleblock_elmt.isNull()) default_titleblock_properties_.fromXml(titleblock_elmt);
if (!conductors_elmt.isNull()) default_conductor_properties_.fromXml(conductors_elmt); if (!conductors_elmt.isNull()) default_conductor_properties_.fromXml(conductors_elmt);
if (!report_elmt.isNull()) setDefaultReportProperties(report_elmt.attribute("label")); if (!report_elmt.isNull()) setDefaultReportProperties(report_elmt.attribute(QStringLiteral("label")));
if (!xref_elmt.isNull()) if (!xref_elmt.isNull())
{ {
foreach(QDomElement elmt, QET::findInDomElement(xref_elmt, "xref")) for (auto elmt : QET::findInDomElement(xref_elmt, QStringLiteral("xref")))
{ {
XRefProperties xrp; XRefProperties xrp;
xrp.fromXml(elmt); xrp.fromXml(elmt);
m_default_xref_properties.insert(elmt.attribute("type"), xrp); m_default_xref_properties.insert(elmt.attribute(QStringLiteral("type")), xrp);
} }
} }
if (!conds_autonums.isNull()) if (!conds_autonums.isNull())
{ {
m_current_conductor_autonum = conds_autonums.attribute("current_autonum"); m_current_conductor_autonum = conds_autonums.attribute(QStringLiteral("current_autonum"));
m_freeze_new_conductors = conds_autonums.attribute("freeze_new_conductors") == "true"; m_freeze_new_conductors = conds_autonums.attribute(QStringLiteral("freeze_new_conductors")) == QLatin1String("true");
foreach (QDomElement elmt, QET::findInDomElement(conds_autonums, "conductor_autonum")) for (auto elmt : QET::findInDomElement(conds_autonums, QStringLiteral("conductor_autonum")))
{ {
NumerotationContext nc; NumerotationContext nc;
nc.fromXml(elmt); nc.fromXml(elmt);
@@ -1527,22 +1527,22 @@ void QETProject::readDefaultPropertiesXml(QDomDocument &xml_project)
} }
if (!folio_autonums.isNull()) if (!folio_autonums.isNull())
{ {
foreach (QDomElement elmt, QET::findInDomElement(folio_autonums, "folio_autonum")) for (auto elmt : QET::findInDomElement(folio_autonums, QStringLiteral("folio_autonum")))
{ {
NumerotationContext nc; NumerotationContext nc;
nc.fromXml(elmt); nc.fromXml(elmt);
m_folio_autonum.insert(elmt.attribute("title"), nc); m_folio_autonum.insert(elmt.attribute(QStringLiteral("title")), nc);
} }
} }
if (!element_autonums.isNull()) if (!element_autonums.isNull())
{ {
m_current_element_autonum = element_autonums.attribute("current_autonum"); m_current_element_autonum = element_autonums.attribute(QStringLiteral("current_autonum"));
m_freeze_new_elements = element_autonums.attribute("freeze_new_elements") == "true"; m_freeze_new_elements = element_autonums.attribute(QStringLiteral("freeze_new_elements")) == QLatin1String("true");
foreach (QDomElement elmt, QET::findInDomElement(element_autonums, "element_autonum")) for (auto elmt : QET::findInDomElement(element_autonums, QStringLiteral("element_autonum")))
{ {
NumerotationContext nc; NumerotationContext nc;
nc.fromXml(elmt); nc.fromXml(elmt);
m_element_autonum.insert(elmt.attribute("title"), nc); m_element_autonum.insert(elmt.attribute(QStringLiteral("title")), nc);
} }
} }
} }