From 25f7aba43d0f4ca38167dd686ae0efd8c89cc5d4 Mon Sep 17 00:00:00 2001 From: Zhangzhi Hu Date: Wed, 30 Oct 2024 00:18:57 +0800 Subject: [PATCH] refactor: replace QString() with QStringLiteral() for better performance --- src/dolphincontextmenu.cpp | 2 +- src/dolphinmainwindow.cpp | 2 +- src/tests/dolphinmainwindowtest.cpp | 2 +- src/tests/dolphinsearchboxtest.cpp | 2 +- src/tests/kfileitemmodeltest.cpp | 10 +++++----- src/tests/kitemlistcontrollertest.cpp | 17 +++++++++-------- 6 files changed, 18 insertions(+), 17 deletions(-) diff --git a/src/dolphincontextmenu.cpp b/src/dolphincontextmenu.cpp index af0ae37c0..77034dadb 100644 --- a/src/dolphincontextmenu.cpp +++ b/src/dolphincontextmenu.cpp @@ -350,7 +350,7 @@ void DolphinContextMenu::insertDefaultItemActions(const KFileItemListProperties addAction(collection->action(KStandardAction::name(KStandardAction::Cut))); addAction(collection->action(KStandardAction::name(KStandardAction::Copy))); if (ContextMenuSettings::showCopyLocation()) { - QAction *copyPathAction = collection->action(QString("copy_location")); + QAction *copyPathAction = collection->action(QStringLiteral("copy_location")); copyPathAction->setEnabled(m_selectedItems.size() == 1); addAction(copyPathAction); } diff --git a/src/dolphinmainwindow.cpp b/src/dolphinmainwindow.cpp index b0eccde0d..a8ef550d6 100644 --- a/src/dolphinmainwindow.cpp +++ b/src/dolphinmainwindow.cpp @@ -2454,7 +2454,7 @@ void DolphinMainWindow::updateFileAndEditActions() QAction *addToPlacesAction = col->action(QStringLiteral("add_to_places")); QAction *copyToOtherViewAction = col->action(QStringLiteral("copy_to_inactive_split_view")); QAction *moveToOtherViewAction = col->action(QStringLiteral("move_to_inactive_split_view")); - QAction *copyLocation = col->action(QString("copy_location")); + QAction *copyLocation = col->action(QStringLiteral("copy_location")); if (list.isEmpty()) { stateChanged(QStringLiteral("has_no_selection")); diff --git a/src/tests/dolphinmainwindowtest.cpp b/src/tests/dolphinmainwindowtest.cpp index 61a72ad51..8fd5be7cb 100644 --- a/src/tests/dolphinmainwindowtest.cpp +++ b/src/tests/dolphinmainwindowtest.cpp @@ -749,7 +749,7 @@ void DolphinMainWindowTest::testAccessibilityAncestorTree() } while (accessibleInterface != accessibleInterfaceOfMainWindow) { QVERIFY2(accessibleInterface, - qPrintable(QString("%1's accessibleInterface or one of its accessible children doesn't have the main window as an ancestor.") + qPrintable(QStringLiteral("%1's accessibleInterface or one of its accessible children doesn't have the main window as an ancestor.") .arg(currentlyFocusedObject->metaObject()->className()))); accessibleInterface = accessibleInterface->parent(); } diff --git a/src/tests/dolphinsearchboxtest.cpp b/src/tests/dolphinsearchboxtest.cpp index f21a75121..bda60909d 100644 --- a/src/tests/dolphinsearchboxtest.cpp +++ b/src/tests/dolphinsearchboxtest.cpp @@ -52,7 +52,7 @@ void DolphinSearchBoxTest::testTextClearing() m_searchBox->setText("xyz"); m_searchBox->setVisible(false, WithoutAnimation); m_searchBox->setVisible(true, WithoutAnimation); - QCOMPARE(m_searchBox->text(), QString("xyz")); + QCOMPARE(m_searchBox->text(), QStringLiteral("xyz")); QTest::keyClick(m_searchBox, Qt::Key_Escape); QVERIFY(m_searchBox->text().isEmpty()); diff --git a/src/tests/kfileitemmodeltest.cpp b/src/tests/kfileitemmodeltest.cpp index fad825dc0..7af5690ff 100644 --- a/src/tests/kfileitemmodeltest.cpp +++ b/src/tests/kfileitemmodeltest.cpp @@ -157,9 +157,9 @@ void KFileItemModelTest::testDefaultSortRole() QVERIFY(itemsInsertedSpy.wait()); QCOMPARE(m_model->count(), 3); - QCOMPARE(m_model->data(0).value("text").toString(), QString("a.txt")); - QCOMPARE(m_model->data(1).value("text").toString(), QString("b.txt")); - QCOMPARE(m_model->data(2).value("text").toString(), QString("c.txt")); + QCOMPARE(m_model->data(0).value("text").toString(), QStringLiteral("a.txt")); + QCOMPARE(m_model->data(1).value("text").toString(), QStringLiteral("b.txt")); + QCOMPARE(m_model->data(2).value("text").toString(), QStringLiteral("c.txt")); } void KFileItemModelTest::testDefaultGroupedSorting() @@ -262,8 +262,8 @@ void KFileItemModelTest::testSetData() QCOMPARE(itemsChangedSpy.count(), 1); values = m_model->data(0); - QCOMPARE(values.value("customRole1").toString(), QString("Test1")); - QCOMPARE(values.value("customRole2").toString(), QString("Test2")); + QCOMPARE(values.value("customRole1").toString(), QStringLiteral("Test1")); + QCOMPARE(values.value("customRole2").toString(), QStringLiteral("Test2")); QVERIFY(m_model->isConsistent()); } diff --git a/src/tests/kitemlistcontrollertest.cpp b/src/tests/kitemlistcontrollertest.cpp index 18ad1186d..de40331e6 100644 --- a/src/tests/kitemlistcontrollertest.cpp +++ b/src/tests/kitemlistcontrollertest.cpp @@ -478,7 +478,7 @@ void KItemListControllerTest::testKeyboardNavigation_data() << qMakePair(KeyPress(Qt::Key_Home), ViewState(0, KItemSet() << 0)); } - const QString testName = layoutNames[layout] + ", " + QString("%1 columns, ").arg(columnCount) + const QString testName = layoutNames[layout] + ", " + QStringLiteral("%1 columns, ").arg(columnCount) + selectionBehaviorNames[selectionBehavior] + ", " + groupingEnabledNames[groupingEnabled] + ", " + layoutDirectionNames[layoutDirection]; @@ -543,13 +543,14 @@ void KItemListControllerTest::testKeyboardNavigation() QTest::keyClick(m_container, key, modifier); - QVERIFY2(m_selectionManager->currentItem() == current, - qPrintable(QString("currentItem() returns index %1 but %2 would be expected. Before this, key \"%3\" was pressed. This test case is defined " - "in row %4 of the testList from KItemListControllerTest::testKeyboardNavigation_data().") - .arg(m_selectionManager->currentItem()) - .arg(current) - .arg(QKeySequence(key).toString()) - .arg(rowCount))); + QVERIFY2( + m_selectionManager->currentItem() == current, + qPrintable(QStringLiteral("currentItem() returns index %1 but %2 would be expected. Before this, key \"%3\" was pressed. This test case is defined " + "in row %4 of the testList from KItemListControllerTest::testKeyboardNavigation_data().") + .arg(m_selectionManager->currentItem()) + .arg(current) + .arg(QKeySequence(key).toString()) + .arg(rowCount))); switch (selectionBehavior) { case KItemListController::NoSelection: QVERIFY(m_selectionManager->selectedItems().isEmpty()); -- 2.47.3