From 90c81d0ecfebeafecde62b15f1fd58bf0afb29d1 Mon Sep 17 00:00:00 2001 From: Kurt Hindenburg Date: Sun, 10 May 2020 16:44:26 -0400 Subject: [PATCH] Simpify return after else statements --- src/Application.cpp | 3 +- src/ColorSchemeManager.cpp | 26 +++++++--------- src/ExtendedCharTable.cpp | 64 ++++++++++++++++++-------------------- src/MainWindow.cpp | 3 +- src/Part.cpp | 15 ++++----- src/ProfileManager.cpp | 3 +- src/ScreenWindow.cpp | 5 ++- src/SessionListModel.cpp | 22 ++++++------- src/ShellCommand.cpp | 5 ++- 9 files changed, 66 insertions(+), 80 deletions(-) diff --git a/src/Application.cpp b/src/Application.cpp index f01499883..ed8baa433 100644 --- a/src/Application.cpp +++ b/src/Application.cpp @@ -550,9 +550,8 @@ Profile::Ptr Application::processProfileChangeArgs(Profile::Ptr baseProfile) if (shouldUseNewProfile) { return newProfile; - } else { - return baseProfile; } + return baseProfile; } void Application::startBackgroundMode(MainWindow *window) diff --git a/src/ColorSchemeManager.cpp b/src/ColorSchemeManager.cpp index 7bcecfaa0..1cbc7aa50 100644 --- a/src/ColorSchemeManager.cpp +++ b/src/ColorSchemeManager.cpp @@ -181,10 +181,9 @@ bool ColorSchemeManager::deleteColorScheme(const QString &name) if (QFile::remove(path)) { delete _colorSchemes.take(name); return true; - } else { - qCDebug(KonsoleDebug)<<"Failed to remove color scheme -"< usedExtendedChars; - const QList sessionsList = SessionManager::instance()->sessions(); - for (const Session *s : sessionsList) { - const QList displayList = s->views(); - for (const TerminalDisplay *display : displayList) { - usedExtendedChars += display->screenWindow()->screen()->usedExtendedChars(); - } + if (hash == initialHash) { + if (!triedCleaningSolution) { + triedCleaningSolution = true; + // All the hashes are full, go to all Screens and try to free any + // This is slow but should happen very rarely + QSet usedExtendedChars; + const QList sessionsList = SessionManager::instance()->sessions(); + for (const Session *s : sessionsList) { + const QList displayList = s->views(); + for (const TerminalDisplay *display : displayList) { + usedExtendedChars += display->screenWindow()->screen()->usedExtendedChars(); } - - QHash::iterator it = _extendedCharTable.begin(); - QHash::iterator itEnd = _extendedCharTable.end(); - while (it != itEnd) { - if (usedExtendedChars.contains(it.key())) { - ++it; - } else { - it = _extendedCharTable.erase(it); - } - } - } else { - qCDebug(KonsoleDebug) << "Using all the extended char hashes, going to miss this extended character"; - return 0; } + + QHash::iterator it = _extendedCharTable.begin(); + QHash::iterator itEnd = _extendedCharTable.end(); + while (it != itEnd) { + if (usedExtendedChars.contains(it.key())) { + ++it; + } else { + it = _extendedCharTable.erase(it); + } + } + } else { + qCDebug(KonsoleDebug) << "Using all the extended char hashes, going to miss this extended character"; + return 0; } } } @@ -121,10 +120,9 @@ uint *ExtendedCharTable::lookupExtendedChar(uint hash, ushort &length) const if (buffer != nullptr) { length = ushort(buffer[0]); return buffer + 1; - } else { - length = 0; - return nullptr; - } + } + length = 0; + return nullptr; } uint ExtendedCharTable::extendedCharHash(const uint *unicodePoints, ushort length) const diff --git a/src/MainWindow.cpp b/src/MainWindow.cpp index 98d2a7d2a..0bc87112e 100644 --- a/src/MainWindow.cpp +++ b/src/MainWindow.cpp @@ -440,9 +440,8 @@ QString MainWindow::activeSessionDir() const session->getDynamicTitle(); } return _pluggedController->currentDir(); - } else { - return QString(); } + return QString(); } void MainWindow::openUrls(const QList &urls) diff --git a/src/Part.cpp b/src/Part.cpp index 924fbd288..c6efd7b3c 100644 --- a/src/Part.cpp +++ b/src/Part.cpp @@ -111,9 +111,8 @@ Session *Part::activeSession() const Q_ASSERT(_viewManager->activeViewController()->session()); return _viewManager->activeViewController()->session(); - } else { - return nullptr; - } + } + return nullptr; } void Part::startProgram(const QString &program, const QStringList &arguments) @@ -176,9 +175,8 @@ int Part::foregroundProcessId() if (activeSession()->isForegroundProcessActive()) { return activeSession()->foregroundProcessId(); - } else { - return -1; - } + } + return -1; } QString Part::foregroundProcessName() @@ -187,9 +185,8 @@ QString Part::foregroundProcessName() if (activeSession()->isForegroundProcessActive()) { return activeSession()->foregroundProcessName(); - } else { - return QString(); - } + } + return QString(); } QString Part::currentWorkingDirectory() const diff --git a/src/ProfileManager.cpp b/src/ProfileManager.cpp index bde6e6b45..4520fdc4c 100644 --- a/src/ProfileManager.cpp +++ b/src/ProfileManager.cpp @@ -176,9 +176,8 @@ Profile::Ptr ProfileManager::loadProfile(const QString& shortPath) if (recursionGuard.contains(path)) { qCDebug(KonsoleDebug) << "Ignoring attempt to load profile recursively from" << path; return _fallbackProfile; - } else { - recursionGuard.push(path); } + recursionGuard.push(path); // load the profile ProfileReader reader; diff --git a/src/ScreenWindow.cpp b/src/ScreenWindow.cpp index 8ee64a3aa..2018a248a 100644 --- a/src/ScreenWindow.cpp +++ b/src/ScreenWindow.cpp @@ -299,9 +299,8 @@ QRect ScreenWindow::scrollRegion() const if (atEndOfOutput() && equalToScreenSize) { return _screen->lastScrolledRegion(); - } else { - return {0, 0, windowColumns(), windowLines()}; - } + } + return {0, 0, windowColumns(), windowLines()}; } void ScreenWindow::notifyOutputChanged() diff --git a/src/SessionListModel.cpp b/src/SessionListModel.cpp index 76cb221ca..661f47e28 100644 --- a/src/SessionListModel.cpp +++ b/src/SessionListModel.cpp @@ -98,15 +98,14 @@ QVariant SessionListModel::headerData(int section, Qt::Orientation orientation, if (orientation == Qt::Vertical) { return QVariant(); - } else { - switch (section) { - case 0: - return i18nc("@item:intable The session index", "Number"); - case 1: - return i18nc("@item:intable The session title", "Title"); - default: - return QVariant(); - } + } + switch (section) { + case 0: + return i18nc("@item:intable The session index", "Number"); + case 1: + return i18nc("@item:intable The session title", "Title"); + default: + return QVariant(); } } @@ -142,7 +141,6 @@ QModelIndex SessionListModel::index(int row, int column, const QModelIndex &pare { if (hasIndex(row, column, parent)) { return createIndex(row, column, _sessions[row]); - } else { - return {}; - } + } + return {}; } diff --git a/src/ShellCommand.cpp b/src/ShellCommand.cpp index 27d06f077..a94370c02 100644 --- a/src/ShellCommand.cpp +++ b/src/ShellCommand.cpp @@ -61,9 +61,8 @@ QString ShellCommand::command() const { if (!_arguments.isEmpty()) { return _arguments[0]; - } else { - return QString(); - } + } + return QString(); } QStringList ShellCommand::arguments() const