┌   ┐
54
└   ┘

summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPeter Penz <[email protected]>2007-01-15 18:28:19 +0000
committerPeter Penz <[email protected]>2007-01-15 18:28:19 +0000
commitd7b618e4bb2879c0cfc773a9839aa37fb8b95a20 (patch)
treef6c410cdb7492f3b8bef44eb983b2893bd1f72f4
parente28a32728b40ac22dd36ea4db136adc2d6f1026d (diff)
Minor performance improvement. As Dominic Battre pointed out correctly, it is not necessary to calculate the value of both numbers, it is enough to compare the weight.
svn path=/trunk/playground/utils/dolphin/; revision=623878
-rw-r--r--src/dolphinsortfilterproxymodel.cpp20
1 files changed, 9 insertions, 11 deletions
diff --git a/src/dolphinsortfilterproxymodel.cpp b/src/dolphinsortfilterproxymodel.cpp
index ad7c98b4d..783a0af42 100644
--- a/src/dolphinsortfilterproxymodel.cpp
+++ b/src/dolphinsortfilterproxymodel.cpp
@@ -184,16 +184,13 @@ int DolphinSortFilterProxyModel::naturalCompare(const QString& a,
//
// The longest run of digits wins. That aside, the greatest
// value wins, but we can't know that it will until we've scanned
- // both numbers to know that they have the same magnitude, so we
- // remember the values in 'valueA' and 'valueB'.
-
- int valueA = 0;
- int valueB = 0;
+ // both numbers to know that they have the same magnitude.
+ int weight = 0;
while (1) {
if (!currA->isDigit() && !currB->isDigit()) {
- if (valueA != valueB) {
- return valueA - valueB;
+ if (weight != 0) {
+ return weight;
}
break;
}
@@ -203,11 +200,12 @@ int DolphinSortFilterProxyModel::naturalCompare(const QString& a,
else if (!currB->isDigit()) {
return +1;
}
- else {
- valueA = (valueA * 10) + currA->digitValue();
- valueB = (valueB * 10) + currB->digitValue();
+ else if ((*currA < *currB) && (weight == 0)) {
+ weight = -1;
+ }
+ else if ((*currA > *currB) && (weight == 0)) {
+ weight = +1;
}
-
++currA;
++currB;
}