[Scummvm-git-logs] scummvm master -> 61b267759ad89e774be0bd8af3732581b006e896

sev- noreply at scummvm.org
Sat Jan 20 22:20:59 UTC 2024


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

Summary:
61b267759a COMMON: Use hashit, hashit_lower, equalsIgnoreCase on Path string


Commit: 61b267759ad89e774be0bd8af3732581b006e896
    https://github.com/scummvm/scummvm/commit/61b267759ad89e774be0bd8af3732581b006e896
Author: Le Philousophe (lephilousophe at users.noreply.github.com)
Date: 2024-01-20T23:20:55+01:00

Commit Message:
COMMON: Use hashit, hashit_lower, equalsIgnoreCase on Path string

This change should be safe as our escape system doesn't mess with case.
In addition, we compare underlying strings to check equality so hashing
its content should work too.

Changed paths:
    common/path.cpp


diff --git a/common/path.cpp b/common/path.cpp
index 66a36814f62..6346930c6e0 100644
--- a/common/path.cpp
+++ b/common/path.cpp
@@ -1011,6 +1011,14 @@ static String getIdentifierComponent(const String &in) {
 	return part;
 }
 
+uint Path::hash() const {
+	return hashit(_str.c_str());
+}
+
+uint Path::hashIgnoreCase() const {
+	return hashit_lower(_str);
+}
+
 // This hash algorithm is inspired by a Python proposal to hash for tuples
 // https://bugs.python.org/issue942952#msg20602
 // As we don't have the length, it's not added in but
@@ -1020,32 +1028,6 @@ struct hasher {
 	uint mult;
 };
 
-uint Path::hash() const {
-	hasher v = { 0x345678, 1000003 };
-	reduceComponents<hasher &>(
-		[](hasher &value, const String &in, bool last) -> hasher & {
-			uint hash = hashit(in.c_str());
-
-			value.result = (value.result + hash) * value.mult;
-			value.mult = (value.mult * 69069);
-			return value;
-		}, v);
-	return v.result;
-}
-
-uint Path::hashIgnoreCase() const {
-	hasher v = { 0x345678, 1000003 };
-	reduceComponents<hasher &>(
-		[](hasher &value, const String &in, bool last) -> hasher & {
-			uint hash = hashit_lower(in);
-
-			value.result = (value.result + hash) * value.mult;
-			value.mult = (value.mult * 69069);
-			return value;
-		}, v);
-	return v.result;
-}
-
 uint Path::hashIgnoreCaseAndMac() const {
 	hasher v = { 0x345678, 1000003 };
 	reduceComponents<hasher &>(
@@ -1067,10 +1049,7 @@ bool Path::matchPattern(const Path &pattern) const {
 }
 
 bool Path::equalsIgnoreCase(const Path &other) const {
-	return compareComponents(
-		[](const String &x, const String &y) {
-			return x.equalsIgnoreCase(y);
-		}, other);
+	return _str.equalsIgnoreCase(other._str);
 }
 
 bool Path::equalsIgnoreCaseAndMac(const Path &other) const {




More information about the Scummvm-git-logs mailing list