[Scummvm-git-logs] scummvm master -> 92606bb7b892773152323e9a8af8ecb9ba446c40

criezy noreply at scummvm.org
Wed Dec 21 12:45:29 UTC 2022


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

Summary:
088c83fcf9 AGS: replace use of equality checks in AGS3::std::set
7e6c494733 AGS: add erase method for elements to AGS3::std::set
92606bb7b8 AGS: improve find for AGS3::std::set


Commit: 088c83fcf9e137b1e174803f44bce8249f74f8cc
    https://github.com/scummvm/scummvm/commit/088c83fcf9e137b1e174803f44bce8249f74f8cc
Author: grisenti (emanuele at grisenti.net)
Date: 2022-12-21T13:45:25+01:00

Commit Message:
AGS: replace use of equality checks in AGS3::std::set

Changed paths:
    engines/ags/lib/std/set.h


diff --git a/engines/ags/lib/std/set.h b/engines/ags/lib/std/set.h
index af15c81ee8c..e33a41d153c 100644
--- a/engines/ags/lib/std/set.h
+++ b/engines/ags/lib/std/set.h
@@ -36,6 +36,11 @@ private:
 	static int ComparatorFn(const T &a, const T &b) {
 		return Comparitor().operator()(a, b) ? -1 : 0;
 	}
+
+	static bool CompareEq(const T &a, const T &b) {
+		return !ComparatorFn(a, b) && !ComparatorFn(b, a);
+	}
+
 public:
 	struct Entry {
 		const T &_value;
@@ -56,7 +61,7 @@ public:
 	 */
 	iterator find(const T &item) {
 		iterator it;
-		for (it = this->begin(); it != this->end() && *it != item; ++it) {
+		for (it = this->begin(); it != this->end() && !CompareEq(*it, item); ++it) {
 		}
 
 		return it;
@@ -76,7 +81,7 @@ public:
 	size_t count(const T item) const {
 		size_t total = 0;
 		for (const_iterator it = this->begin(); it != this->end(); ++it) {
-			if (*it == item)
+			if (CompareEq(*it, item))
 				++total;
 			else if (!ComparatorFn(item, *it))
 				// Passed beyond possibility of matches


Commit: 7e6c4947334866074457735f4706b6382d07bf61
    https://github.com/scummvm/scummvm/commit/7e6c4947334866074457735f4706b6382d07bf61
Author: grisenti (emanuele at grisenti.net)
Date: 2022-12-21T13:45:25+01:00

Commit Message:
AGS: add erase method for elements to AGS3::std::set

Changed paths:
    engines/ags/lib/std/set.h


diff --git a/engines/ags/lib/std/set.h b/engines/ags/lib/std/set.h
index e33a41d153c..9d3c95f4642 100644
--- a/engines/ags/lib/std/set.h
+++ b/engines/ags/lib/std/set.h
@@ -75,6 +75,37 @@ public:
 		return Entry(item);
 	}
 
+	/**
+	 * Removes the element at the given iterator
+	 */
+	void erase(iterator item) {
+		Common::SortedArray<T, const T &>::erase(item);
+	}
+
+	/**
+	 * Removes the elements at the specified range
+	 */
+	void erase(iterator first, iterator last) {
+		Common::SortedArray<T, const T &>::erase(first, last);
+	}
+
+	/**
+	 * Removes the elements equal to the given item.
+	 * Returns the number of elements removed
+	 */
+	size_t erase(const T &item) {
+		iterator first = find(item);
+		if (first == this->end())
+			return 0;
+		iterator end = first + 1;
+		while (end != this->end() && CompareEq(*first, *end)) {
+			++end;
+		}
+		size_t erased = Common::distance(first, end);
+		this->erase(first, end);
+		return erased;
+	}
+
 	/**
 	 * Returns the number of keys that match the specified key
 	 */


Commit: 92606bb7b892773152323e9a8af8ecb9ba446c40
    https://github.com/scummvm/scummvm/commit/92606bb7b892773152323e9a8af8ecb9ba446c40
Author: grisenti (emanuele at grisenti.net)
Date: 2022-12-21T13:45:25+01:00

Commit Message:
AGS: improve find for AGS3::std::set

Changed paths:
    engines/ags/lib/std/set.h


diff --git a/engines/ags/lib/std/set.h b/engines/ags/lib/std/set.h
index 9d3c95f4642..0bac0483817 100644
--- a/engines/ags/lib/std/set.h
+++ b/engines/ags/lib/std/set.h
@@ -60,11 +60,18 @@ public:
 	 * Locate an item in the set
 	 */
 	iterator find(const T &item) {
-		iterator it;
-		for (it = this->begin(); it != this->end() && !CompareEq(*it, item); ++it) {
+		iterator begin = this->begin();
+		iterator end = this->end();
+		while (begin < end) {
+			iterator mid = begin + (Common::distance(begin, end) / 2);
+			if (ComparatorFn(item, *mid))
+				end = mid;
+			else if (ComparatorFn(*mid, item))
+			 	begin = mid + 1;
+			else
+				return mid;
 		}
-
-		return it;
+		return this->end();
 	}
 
 	/**




More information about the Scummvm-git-logs mailing list