aboutsummaryrefslogtreecommitdiffstats
path: root/src/libs/utils/differ.cpp
diff options
context:
space:
mode:
authorAlessandro Portale <alessandro.portale@qt.io>2020-01-15 19:10:34 +0100
committerAlessandro Portale <alessandro.portale@qt.io>2020-01-20 20:56:57 +0000
commit24a25eed1481a7c563431d79e3ad07840c0f7125 (patch)
tree3eb8a56dac620a31e6af362bf7c03201ea645771 /src/libs/utils/differ.cpp
parentad4040972b9d763b2ceaa7444d18e65dd3da2ee9 (diff)
Use isEmpty() instead of count() or size()
Change-Id: I0a89d2808c6d041da0dc41ea5aea58e6e8759bb4 Reviewed-by: Orgad Shaneh <orgads@gmail.com>
Diffstat (limited to 'src/libs/utils/differ.cpp')
-rw-r--r--src/libs/utils/differ.cpp31
1 files changed, 15 insertions, 16 deletions
diff --git a/src/libs/utils/differ.cpp b/src/libs/utils/differ.cpp
index 74ec99c78c..8fb4cf4ad4 100644
--- a/src/libs/utils/differ.cpp
+++ b/src/libs/utils/differ.cpp
@@ -206,7 +206,7 @@ static int cleanupSemanticsScore(const QString &text1, const QString &text2)
const QRegularExpression blankLineStart("^\\r?\\n\\r?\\n");
const QRegularExpression sentenceEnd("\\. $");
- if (!text1.count() || !text2.count()) // Edges
+ if (text1.isEmpty() || text2.isEmpty()) // Edges
return 6;
const QChar char1 = text1[text1.count() - 1];
@@ -551,13 +551,12 @@ static QString encodeExpandedWhitespace(const QString &leftEquality,
return QString(); // equalities broken
}
- if ((leftWhitespaces.count() && !rightWhitespaces.count())
- || (!leftWhitespaces.count() && rightWhitespaces.count())) {
+ if (leftWhitespaces.isEmpty() ^ rightWhitespaces.isEmpty()) {
// there must be at least 1 corresponding whitespace, equalities broken
return QString();
}
- if (leftWhitespaces.count() && rightWhitespaces.count()) {
+ if (!leftWhitespaces.isEmpty() && !rightWhitespaces.isEmpty()) {
const int replacementPosition = output.count();
const int replacementSize = qMax(leftWhitespaces.count(), rightWhitespaces.count());
const QString replacement(replacementSize, ' ');
@@ -723,10 +722,10 @@ static void appendWithEqualitiesSquashed(const QList<Diff> &leftInput,
QList<Diff> *leftOutput,
QList<Diff> *rightOutput)
{
- if (leftInput.count()
- && rightInput.count()
- && leftOutput->count()
- && rightOutput->count()
+ if (!leftInput.isEmpty()
+ && !rightInput.isEmpty()
+ && !leftOutput->isEmpty()
+ && !rightOutput->isEmpty()
&& leftInput.first().command == Diff::Equal
&& rightInput.first().command == Diff::Equal
&& leftOutput->last().command == Diff::Equal
@@ -1245,7 +1244,7 @@ QList<Diff> Differ::diffNonCharMode(const QString &text1, const QString &text2)
} else if (diffItem.command == Diff::Insert) {
lastInsert += diffItem.text;
} else { // Diff::Equal
- if (lastDelete.count() || lastInsert.count()) {
+ if (!(lastDelete.isEmpty() && lastInsert.isEmpty())) {
// Rediff here on char basis
newDiffList += preprocess1AndDiff(lastDelete, lastInsert);
@@ -1334,7 +1333,7 @@ QList<Diff> Differ::merge(const QList<Diff> &diffList)
} else if (diff.command == Diff::Insert) {
lastInsert += diff.text;
} else { // Diff::Equal
- if (lastDelete.count() || lastInsert.count()) {
+ if (!(lastDelete.isEmpty() && lastInsert.isEmpty())) {
// common prefix
const int prefixCount = commonPrefix(lastDelete, lastInsert);
@@ -1343,7 +1342,7 @@ QList<Diff> Differ::merge(const QList<Diff> &diffList)
lastDelete = lastDelete.mid(prefixCount);
lastInsert = lastInsert.mid(prefixCount);
- if (newDiffList.count()
+ if (!newDiffList.isEmpty()
&& newDiffList.last().command == Diff::Equal) {
newDiffList.last().text += prefix;
} else {
@@ -1362,20 +1361,20 @@ QList<Diff> Differ::merge(const QList<Diff> &diffList)
}
// append delete / insert / equal
- if (lastDelete.count())
+ if (!lastDelete.isEmpty())
newDiffList.append(Diff(Diff::Delete, lastDelete));
- if (lastInsert.count())
+ if (!lastInsert.isEmpty())
newDiffList.append(Diff(Diff::Insert, lastInsert));
- if (diff.text.count())
+ if (!diff.text.isEmpty())
newDiffList.append(diff);
lastDelete.clear();
lastInsert.clear();
} else { // join with last equal diff
- if (newDiffList.count()
+ if (!newDiffList.isEmpty()
&& newDiffList.last().command == Diff::Equal) {
newDiffList.last().text += diff.text;
} else {
- if (diff.text.count())
+ if (!diff.text.isEmpty())
newDiffList.append(diff);
}
}