[prev in list] [next in list] [prev in thread] [next in thread] 

List:       kde-commits
Subject:    [konsole] src: use auto range loops
From:       Kurt Hindenburg <null () kde ! org>
Date:       2017-04-01 2:20:59
Message-ID: E1cu8ex-00065j-H9 () code ! kde ! org
[Download RAW message or body]

Git commit 5a15d20def8714e9eb34978f4ee144a64bc6656e by Kurt Hindenburg.
Committed on 01/04/2017 at 02:21.
Pushed by hindenburg into branch 'master'.

use auto range loops

M  +2    -2    src/Emulation.cpp
M  +5    -5    src/ProfileManager.cpp
M  +4    -8    src/SessionController.cpp
M  +3    -3    src/ViewManager.cpp
M  +9    -9    src/autotests/ProfileTest.cpp
M  +2    -2    src/konsole_wcwidth.cpp

https://commits.kde.org/konsole/5a15d20def8714e9eb34978f4ee144a64bc6656e

diff --git a/src/Emulation.cpp b/src/Emulation.cpp
index e5abe79a..2e9dbe8e 100644
--- a/src/Emulation.cpp
+++ b/src/Emulation.cpp
@@ -221,8 +221,8 @@ void Emulation::receiveData(const char* text, int length)
     QString unicodeText = _decoder->toUnicode(text, length);
 
     //send characters to terminal emulator
-    for (int i = 0; i < unicodeText.length(); i++)
-        receiveChar(unicodeText[i].unicode());
+    for (auto && i : unicodeText)
+        receiveChar(i.unicode());
 
     //look for z-modem indicator
     //-- someone who understands more about z-modems that I do may be able to move
diff --git a/src/ProfileManager.cpp b/src/ProfileManager.cpp
index 7ca96326..b4840cfe 100644
--- a/src/ProfileManager.cpp
+++ b/src/ProfileManager.cpp
@@ -237,15 +237,15 @@ void ProfileManager::sortProfiles(QList<Profile::Ptr>& list)
     QList<Profile::Ptr> lackingIndices;
     QList<Profile::Ptr> havingIndices;
 
-    for (int i = 0; i < list.size(); ++i) {
+    for (const auto & i : list) {
         // dis-regard the fallback profile
-        if (list.at(i)->path() == _fallbackProfile->path())
+        if (i->path() == _fallbackProfile->path())
             continue;
 
-        if (list.at(i)->menuIndexAsInt() == 0)
-            lackingIndices.append(list.at(i));
+        if (i->menuIndexAsInt() == 0)
+            lackingIndices.append(i);
         else
-            havingIndices.append(list.at(i));
+            havingIndices.append(i);
     }
 
     // sort by index
diff --git a/src/SessionController.cpp b/src/SessionController.cpp
index 99fa3c28..cb99a6ed 100644
--- a/src/SessionController.cpp
+++ b/src/SessionController.cpp
@@ -1007,10 +1007,7 @@ void SessionController::copyInputToAllTabs()
 
     QSet<Session*> group =
         QSet<Session*>::fromList(SessionManager::instance()->sessions());
-    for (QSet<Session*>::iterator iterator = group.begin();
-            iterator != group.end(); ++iterator) {
-        Session* session = *iterator;
-
+    for (auto session : group) {
         // First, ensure that the session is removed
         // (necessary to avoid duplicates on addSession()!)
         _copyToGroup->removeSession(session);
@@ -1073,12 +1070,11 @@ void SessionController::copyInputToNone()
 
     QSet<Session*> group =
         QSet<Session*>::fromList(SessionManager::instance()->sessions());
-    for (QSet<Session*>::iterator iterator = group.begin();
-            iterator != group.end(); ++iterator) {
-        Session* session = *iterator;
+    for (auto iterator : group) {
+        Session* session = iterator;
 
         if (session != _session) {
-            _copyToGroup->removeSession(*iterator);
+            _copyToGroup->removeSession(iterator);
         }
     }
     delete _copyToGroup;
diff --git a/src/ViewManager.cpp b/src/ViewManager.cpp
index 770ea9f9..0d3d2bf8 100644
--- a/src/ViewManager.cpp
+++ b/src/ViewManager.cpp
@@ -1010,9 +1010,9 @@ int ViewManager::newSession(const QString& profile, const QString& directory)
     const QList<Profile::Ptr> profilelist = ProfileManager::instance()->allProfiles();
     Profile::Ptr profileptr = ProfileManager::instance()->defaultProfile();
 
-    for (int i = 0; i < profilelist.size(); ++i) {
-        if (profilelist.at(i)->name() == profile) {
-            profileptr = profilelist.at(i);
+    for (const auto & i : profilelist) {
+        if (i->name() == profile) {
+            profileptr = i;
             break;
         }
     }
diff --git a/src/autotests/ProfileTest.cpp b/src/autotests/ProfileTest.cpp
index 6fd3e766..4062193d 100644
--- a/src/autotests/ProfileTest.cpp
+++ b/src/autotests/ProfileTest.cpp
@@ -129,9 +129,9 @@ void ProfileTest::testProfileGroup()
 {
     // create three new profiles
     Profile::Ptr profile[3];
-    for (int i = 0; i < 3; i++) {
-        profile[i] = new Profile;
-        QVERIFY(!profile[i]->asGroup());
+    for (auto & i : profile) {
+        i = new Profile;
+        QVERIFY(!i->asGroup());
     }
 
     // set properties with different values
@@ -139,18 +139,18 @@ void ProfileTest::testProfileGroup()
     profile[1]->setProperty(Profile::UseCustomCursorColor, false);
 
     // set properties with same values
-    for (int i = 0; i < 3; i++)
-        profile[i]->setProperty(Profile::HistorySize, 1234);
+    for (auto & i : profile)
+        i->setProperty(Profile::HistorySize, 1234);
 
     // create a group profile
     ProfileGroup::Ptr group = ProfileGroup::Ptr(new ProfileGroup);
     const ProfileGroup::Ptr group_const = ProfileGroup::Ptr(new ProfileGroup);
     QVERIFY(group->asGroup());
     QVERIFY(group_const->asGroup());
-    for (int i = 0; i < 3; i++) {
-        group->addProfile(profile[i]);
-        QVERIFY(group->profiles().contains(profile[i]));
-        QVERIFY(!group_const->profiles().contains(profile[i]));
+    for (auto & i : profile) {
+        group->addProfile(i);
+        QVERIFY(group->profiles().contains(i));
+        QVERIFY(!group_const->profiles().contains(i));
     }
     group->updateValues();
 
diff --git a/src/konsole_wcwidth.cpp b/src/konsole_wcwidth.cpp
index 212bc1b5..ff90ccff 100644
--- a/src/konsole_wcwidth.cpp
+++ b/src/konsole_wcwidth.cpp
@@ -223,8 +223,8 @@ int KONSOLEPRIVATE_EXPORT konsole_wcwidth(quint16 oucs)
 int string_width(const QString& text)
 {
     int w = 0;
-    for (int i = 0; i < text.length(); ++i)
-        w += konsole_wcwidth(text[i].unicode());
+    for (auto i : text)
+        w += konsole_wcwidth(i.unicode());
     return w;
 }
 
[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic