[Scummvm-git-logs] scummvm master -> 2f19102f44e2d51d45062b4f929870705e32c4c5

sev- noreply at scummvm.org
Wed Sep 20 00:16:29 UTC 2023


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:
e5e9d5c96d COMMON: Performance improvement for toUppercase and toLowercase: Avoid calling makeUnique on strings that aren't modifie
2f19102f44 COMMON: Avoid calling punycode_decodefilename on strings that aren't punycode.


Commit: e5e9d5c96dd6b9f1c17e59c9e1768e042d80db6b
    https://github.com/scummvm/scummvm/commit/e5e9d5c96dd6b9f1c17e59c9e1768e042d80db6b
Author: elasota (ejlasota at gmail.com)
Date: 2023-09-20T02:16:25+02:00

Commit Message:
COMMON: Performance improvement for toUppercase and toLowercase: Avoid calling makeUnique on strings that aren't modified.

Changed paths:
    common/str-base.cpp
    common/str-base.h


diff --git a/common/str-base.cpp b/common/str-base.cpp
index 71ae708a499..b489fd3600a 100644
--- a/common/str-base.cpp
+++ b/common/str-base.cpp
@@ -720,21 +720,37 @@ TEMPLATE void BASESTRING::wordWrap(const uint32 maxLength) {
 #endif
 
 TEMPLATE void BASESTRING::toLowercase() {
-	makeUnique();
-	for (uint32 i = 0; i < _size; ++i) {
-		if (_str[i] > 0 && _str[i] < 128) {
-			_str[i] = tolower(_str[i]);
-		}
-	}
+	toCase(tolower);
 }
 
 TEMPLATE void BASESTRING::toUppercase() {
-	makeUnique();
-	for (uint32 i = 0; i < _size; ++i) {
-		if (_str[i] > 0 && _str[i] < 128) {
-			_str[i] = toupper(_str[i]);
+	toCase(toupper);
+}
+
+TEMPLATE void BASESTRING::toCase(int (*caseChangeFunc)(int)) {
+	uint32 sz = _size;
+	T *buf = _str;
+
+	uint32 i = 0;
+	for ( ; i < sz; ++i) {
+		value_type ch = buf[i];
+		if (ch > 0 && ch < 128) {
+			value_type newCh = static_cast<value_type>(caseChangeFunc(buf[i]));
+			if (ch != newCh) {
+				makeUnique();
+				buf = _str;
+				buf[i] = newCh;
+				i++;
+				break;
+			}
 		}
 	}
+
+	for (; i < sz; ++i) {
+		value_type ch = buf[i];
+		if (ch > 0 && ch < 128)
+			buf[i] = static_cast<value_type>(caseChangeFunc(ch));
+	}
 }
 
 #ifndef SCUMMVM_UTIL
diff --git a/common/str-base.h b/common/str-base.h
index aeb11885c6c..b8e447236e1 100644
--- a/common/str-base.h
+++ b/common/str-base.h
@@ -263,6 +263,8 @@ protected:
 
 	uint getUnsignedValue(uint pos) const;
 
+	void toCase(int (*caseChangeFunc)(int));
+
 	static uint32 cStrLen(const value_type *str);
 };
 }


Commit: 2f19102f44e2d51d45062b4f929870705e32c4c5
    https://github.com/scummvm/scummvm/commit/2f19102f44e2d51d45062b4f929870705e32c4c5
Author: elasota (ejlasota at gmail.com)
Date: 2023-09-20T02:16:25+02:00

Commit Message:
COMMON: Avoid calling punycode_decodefilename on strings that aren't punycode.

Changed paths:
    common/fs.cpp


diff --git a/common/fs.cpp b/common/fs.cpp
index 936d5b46324..35536e417aa 100644
--- a/common/fs.cpp
+++ b/common/fs.cpp
@@ -168,8 +168,13 @@ U32String FSNode::getDisplayName() const {
 
 String FSNode::getName() const {
 	assert(_realNode);
+
 	// We transparently decode any punycode-named files
-	return punycode_decodefilename(_realNode->getName());
+	String name = _realNode->getName();
+	if (!punycode_hasprefix(name))
+		return name;
+
+	return punycode_decodefilename(name);
 }
 
 String FSNode::getFileName() const {




More information about the Scummvm-git-logs mailing list