From 2ba40d5ea9c99a3b5c40874cb4eb3d2c28923639 Mon Sep 17 00:00:00 2001 From: Marco Bubke Date: Wed, 31 Aug 2022 11:09:29 +0200 Subject: [PATCH] QmlDesigner: Move code to compile time Instead of initialize code at run runtime we can do that already at compile time. And because Qt has already QStringView overloads we can use them. Change-Id: I2a6a2c45d6c5cd1af2c64e32deeb3d4ff81c9ee0 Reviewed-by: Tim Jenssen --- .../designercore/model/rewriterview.cpp | 39 +++++++------------ 1 file changed, 14 insertions(+), 25 deletions(-) diff --git a/src/plugins/qmldesigner/designercore/model/rewriterview.cpp b/src/plugins/qmldesigner/designercore/model/rewriterview.cpp index 4ed69e89d67..63ece33a4d3 100644 --- a/src/plugins/qmldesigner/designercore/model/rewriterview.cpp +++ b/src/plugins/qmldesigner/designercore/model/rewriterview.cpp @@ -41,7 +41,8 @@ using namespace QmlDesigner::Internal; namespace QmlDesigner { -const char annotationsEscapeSequence[] = "##^##"; +constexpr QStringView annotationsStart{u"/*##^##"}; +constexpr QStringView annotationsEnd{u"##^##*/"}; bool debugQmlPuppet(const DesignerSettings &settings) { @@ -1103,29 +1104,17 @@ void RewriterView::delayedSetup() m_textToModelMerger->delayedSetup(); } -static QString annotationsEnd() -{ - const static QString end = QString("%1*/").arg(annotationsEscapeSequence); - return end; -} - -static QString annotationsStart() -{ - const static QString start = QString("/*%1").arg(annotationsEscapeSequence); - return start; -} - QString RewriterView::getRawAuxiliaryData() const { QTC_ASSERT(m_textModifier, return {}); const QString oldText = m_textModifier->text(); - int startIndex = oldText.indexOf(annotationsStart()); - int endIndex = oldText.indexOf(annotationsEnd()); + int startIndex = oldText.indexOf(annotationsStart); + int endIndex = oldText.indexOf(annotationsEnd); if (startIndex > 0 && endIndex > 0) - return oldText.mid(startIndex, endIndex - startIndex + annotationsEnd().length()); + return oldText.mid(startIndex, endIndex - startIndex + annotationsEnd.length()); return {}; } @@ -1136,8 +1125,8 @@ void RewriterView::writeAuxiliaryData() const QString oldText = m_textModifier->text(); - const int startIndex = oldText.indexOf(annotationsStart()); - const int endIndex = oldText.indexOf(annotationsEnd()); + const int startIndex = oldText.indexOf(annotationsStart); + const int endIndex = oldText.indexOf(annotationsEnd); QString auxData = auxiliaryDataAsQML(); @@ -1145,16 +1134,16 @@ void RewriterView::writeAuxiliaryData() if (!auxData.isEmpty()) { auxData.prepend("\n"); - auxData.prepend(annotationsStart()); + auxData.prepend(annotationsStart); if (!replace) auxData.prepend("\n"); - auxData.append(annotationsEnd()); + auxData.append(annotationsEnd); if (!replace) auxData.append("\n"); } if (replace) - m_textModifier->replace(startIndex, endIndex - startIndex + annotationsEnd().length(), auxData); + m_textModifier->replace(startIndex, endIndex - startIndex + annotationsEnd.length(), auxData); else m_textModifier->replace(oldText.length(), 0, auxData); } @@ -1222,12 +1211,12 @@ void RewriterView::restoreAuxiliaryData() const QString text = m_textModifier->text(); - int startIndex = text.indexOf(annotationsStart()); - int endIndex = text.indexOf(annotationsEnd()); + int startIndex = text.indexOf(annotationsStart); + int endIndex = text.indexOf(annotationsEnd); if (startIndex > 0 && endIndex > 0) { - const QString auxSource = text.mid(startIndex + annotationsStart().length(), - endIndex - startIndex - annotationsStart().length()); + const QString auxSource = text.mid(startIndex + annotationsStart.length(), + endIndex - startIndex - annotationsStart.length()); QmlJS::SimpleReader reader; checkChildNodes(reader.readFromSource(auxSource), this); }