[Scummvm-git-logs] scummvm master -> 4f83f8f6250d7bfd9c6b0cd7e6c4579bcacfa23d

sev- noreply at scummvm.org
Mon Aug 28 20:04:31 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:
20c91ae391 COMMON: Move string length calculation to a separate function so it's easier to get through string constructors with jus
4f83f8f625 COMMON: Use standard library strlen for char string lengths.


Commit: 20c91ae3912e4e92fe0c238e5017648f00b43b6f
    https://github.com/scummvm/scummvm/commit/20c91ae3912e4e92fe0c238e5017648f00b43b6f
Author: elasota (ejlasota at gmail.com)
Date: 2023-08-28T22:04:26+02:00

Commit Message:
COMMON: Move string length calculation to a separate function so it's easier to get through string constructors with just Step Over while debugging (vs. Step Out which has a 2-key default keybind in VS and can behave badly with optimizations enabled).

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


diff --git a/common/str-base.cpp b/common/str-base.cpp
index 54d02b20865..4e92d079eda 100644
--- a/common/str-base.cpp
+++ b/common/str-base.cpp
@@ -106,14 +106,8 @@ TEMPLATE BASESTRING::BaseString(const value_type *str) : _size(0), _str(_storage
 	if (str == nullptr) {
 		_storage[0] = 0;
 		_size = 0;
-	} else {
-		uint32 len = 0;
-		const value_type *s = str;
-		while (*s++) {
-			++len;
-		}
-		initWithValueTypeStr(str, len);
-	}
+	} else
+		initWithValueTypeStr(str, cStrLen(str));
 }
 
 TEMPLATE BASESTRING::BaseString(const value_type *str, uint32 len) : _size(0), _str(_storage) {
@@ -841,6 +835,14 @@ TEMPLATE uint BASESTRING::getUnsignedValue(uint pos) const {
 	return ((uint)_str[pos]) << shift >> shift;
 }
 
+TEMPLATE uint32 BASESTRING::cStrLen(const value_type *str) {
+	uint32 len = 0;
+	while (str[len])
+		len++;
+
+	return len;
+}
+
 // Hash function for strings, taken from CPython.
 TEMPLATE uint BASESTRING::hash() const {
 	uint hashResult = getUnsignedValue(0) << 7;
diff --git a/common/str-base.h b/common/str-base.h
index aa530c5c0e7..19e9b94f3c3 100644
--- a/common/str-base.h
+++ b/common/str-base.h
@@ -259,6 +259,8 @@ protected:
 	bool pointerInOwnBuffer(const value_type *str) const;
 
 	uint getUnsignedValue(uint pos) const;
+
+	static uint32 cStrLen(const value_type *str);
 };
 }
 #endif


Commit: 4f83f8f6250d7bfd9c6b0cd7e6c4579bcacfa23d
    https://github.com/scummvm/scummvm/commit/4f83f8f6250d7bfd9c6b0cd7e6c4579bcacfa23d
Author: elasota (ejlasota at gmail.com)
Date: 2023-08-28T22:04:26+02:00

Commit Message:
COMMON: Use standard library strlen for char string lengths.

Changed paths:
    common/str-base.cpp


diff --git a/common/str-base.cpp b/common/str-base.cpp
index 4e92d079eda..b74e11db0a0 100644
--- a/common/str-base.cpp
+++ b/common/str-base.cpp
@@ -852,6 +852,11 @@ TEMPLATE uint BASESTRING::hash() const {
 	return hashResult ^ _size;
 }
 
+template<>
+uint32 BaseString<char>::cStrLen(const value_type *str) {
+	return static_cast<uint32>(strlen(str));
+}
+
 template class BaseString<char>;
 template class BaseString<uint16>;
 template class BaseString<u32char_type_t>;




More information about the Scummvm-git-logs mailing list