[Scummvm-cvs-logs] scummvm master -> 5ad9cd1a1a18bc97ff0bc651f9704e8fa0c7eedb

tramboi bertrand_augereau at yahoo.fr
Tue Nov 10 20:38:37 CET 2015


This automated email contains information about 2 new commits which have been
pushed to the 'scummvm' repo located at https://github.com/scummvm/scummvm .

Summary:
1311fe5c49 COMMON: Avoid useless (and dangerous when cctor/operator= don't support it) SWAP(x, x) in sorting
5ad9cd1a1a COMMON: More sort unit tests


Commit: 1311fe5c49146b14a476f47c10529931a467ff98
    https://github.com/scummvm/scummvm/commit/1311fe5c49146b14a476f47c10529931a467ff98
Author: Bertrand Augereau (bertrand.augereau at gmail.com)
Date: 2015-11-10T20:08:19+01:00

Commit Message:
COMMON: Avoid useless (and dangerous when cctor/operator= don't support it) SWAP(x, x) in sorting

Changed paths:
    common/algorithm.h



diff --git a/common/algorithm.h b/common/algorithm.h
index 6453073..cbd6eae 100644
--- a/common/algorithm.h
+++ b/common/algorithm.h
@@ -177,7 +177,8 @@ T sortChoosePivot(T first, T last) {
 template<typename T, class StrictWeakOrdering>
 T sortPartition(T first, T last, T pivot, StrictWeakOrdering &comp) {
 	--last;
-	SWAP(*pivot, *last);
+	if (pivot != last)
+		SWAP(*pivot, *last);
 
 	T sorted;
 	for (sorted = first; first != last; ++first) {
@@ -188,7 +189,8 @@ T sortPartition(T first, T last, T pivot, StrictWeakOrdering &comp) {
 		}
 	}
 
-	SWAP(*last, *sorted);
+	if (last != sorted)
+		SWAP(*last, *sorted);
 	return sorted;
 }
 


Commit: 5ad9cd1a1a18bc97ff0bc651f9704e8fa0c7eedb
    https://github.com/scummvm/scummvm/commit/5ad9cd1a1a18bc97ff0bc651f9704e8fa0c7eedb
Author: Bertrand Augereau (bertrand.augereau at gmail.com)
Date: 2015-11-10T20:30:51+01:00

Commit Message:
COMMON: More sort unit tests

Changed paths:
    test/common/algorithm.h



diff --git a/test/common/algorithm.h b/test/common/algorithm.h
index 6eecae3..ccf6469 100644
--- a/test/common/algorithm.h
+++ b/test/common/algorithm.h
@@ -47,10 +47,28 @@ public:
 
 	void test_pod_sort() {
 		{
+			int dummy;
+			Common::sort(&dummy, &dummy);
+			TS_ASSERT_EQUALS(checkSort(&dummy, &dummy, Common::Less<int>()), true);
+		}
+		{
+			int array[] = { 12 };
+			Common::sort(array, ARRAYEND(array));
+			TS_ASSERT_EQUALS(checkSort(array, ARRAYEND(array), Common::Less<int>()), true);
+
+			// already sorted
+			Common::sort(array, ARRAYEND(array));
+			TS_ASSERT_EQUALS(checkSort(array, ARRAYEND(array), Common::Less<int>()), true);
+		}
+		{
 			int array[] = { 63, 11, 31, 72, 1, 48, 32, 69, 38, 31 };
 			Common::sort(array, ARRAYEND(array));
 			TS_ASSERT_EQUALS(checkSort(array, ARRAYEND(array), Common::Less<int>()), true);
 
+			int sortedArray[] = { 1, 11, 31, 31, 32, 38, 48, 63, 69, 72 };
+			for (size_t i = 0; i < 10; ++i)
+				TS_ASSERT_EQUALS(array[i], sortedArray[i]);
+
 			// already sorted
 			Common::sort(array, ARRAYEND(array));
 			TS_ASSERT_EQUALS(checkSort(array, ARRAYEND(array), Common::Less<int>()), true);






More information about the Scummvm-git-logs mailing list