[Scummvm-git-logs] scummvm master -> 3daa6feba1ece4cb548af24e48fc393da0199338

Strangerke noreply at scummvm.org
Wed Feb 4 23:15:09 UTC 2026


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

Summary:
3daa6feba1 M4: Small refactoring in mem, remove 2 gotos


Commit: 3daa6feba1ece4cb548af24e48fc393da0199338
    https://github.com/scummvm/scummvm/commit/3daa6feba1ece4cb548af24e48fc393da0199338
Author: Strangerke (arnaud.boutonne at gmail.com)
Date: 2026-02-05T00:05:22+01:00

Commit Message:
M4: Small refactoring in mem, remove 2 gotos

Changed paths:
    engines/m4/mem/mem.cpp
    engines/m4/mem/res.cpp


diff --git a/engines/m4/mem/mem.cpp b/engines/m4/mem/mem.cpp
index b641f6d7a04..5b81bbb4c1b 100644
--- a/engines/m4/mem/mem.cpp
+++ b/engines/m4/mem/mem.cpp
@@ -38,7 +38,7 @@ void mem_stash_init(int16 num_types) {
 	}
 }
 
-void mem_stash_shutdown(void) {
+void mem_stash_shutdown() {
 	for (int i = 0; i < _MEMTYPE_LIMIT; i++) {
 		if (_G(memBlock)[i]) {
 			mem_free(_G(memBlock)[i]);
@@ -49,16 +49,15 @@ void mem_stash_shutdown(void) {
 
 bool mem_register_stash_type(int32 *memType, int32 blockSize, int32 maxNumRequests, const Common::String &name) {
 	int32 i = 0;
-	bool found = false;
 
-	while ((i < _MEMTYPE_LIMIT) && (_G(sizeMem)[i] > 0) && (!found)) {
+	while (i < _MEMTYPE_LIMIT && _G(sizeMem)[i] > 0) {
 		i++;
 	}
 	if (i == _MEMTYPE_LIMIT)
 		error_show(FL, 'MSIF', "stash: %s", name.c_str());
 
 	// Found a slot
-	if (found || (i < _MEMTYPE_LIMIT)) {
+	if (i < _MEMTYPE_LIMIT) {
 		_G(sizeMem)[i] = blockSize;
 		*memType = i;
 
@@ -78,7 +77,7 @@ bool mem_register_stash_type(int32 *memType, int32 blockSize, int32 maxNumReques
 void mem_free_to_stash(void *mem, int32 memType) {
 	// _G(memBlock)[memType] is block associated with memType
 	int8 *b_ptr = (int8 *)_G(memBlock)[memType];
-	int32 index = ((intptr)mem - (intptr)_G(memBlock)[memType]) / (_G(sizeMem)[memType] + sizeof(uintptr));
+	const int32 index = ((intptr)mem - (intptr)_G(memBlock)[memType]) / (_G(sizeMem)[memType] + sizeof(uintptr));
 
 	if (index < 0 || index > _G(requests)[memType])
 		error_show(FL, 'MSGF');
@@ -103,7 +102,7 @@ void *mem_get_from_stash(int32 memType, const Common::String &name) {
 	}
 
 	error_show(FL, 'OOS!', "stash full %s", name.c_str());
-	return 0;
+	return nullptr;
 }
 
 char *mem_strdup(const char *str) {
diff --git a/engines/m4/mem/res.cpp b/engines/m4/mem/res.cpp
index 9295e1d1bae..39c5e6bfe41 100644
--- a/engines/m4/mem/res.cpp
+++ b/engines/m4/mem/res.cpp
@@ -40,42 +40,35 @@ Resources::~Resources() {
 
 
 Resources::Entry *Resources::findAndSetResEntry(const Common::String &resourceName) {
-	int orig_hash_val;
 	int hash_val;
 	Entry *res = nullptr;
 
 	Common::String resName = resourceName;
 	if (_useLowercase)
 		resName.toLowercase();
-	orig_hash_val = hash_val = hash(resName);
+	const int orig_hash_val = hash_val = hash(resName);
 
 	// If empty slot at this hash, then we're done
-	if (!_resources[hash_val].Flags)
-		goto got_one;
-
-	// Flags is set, so scan until Flags is clear, or the resource name strings match
-	while ((_resources[hash_val].Flags & FULLY_BUFFERED)
-			&& !resName.equals(_resources[hash_val].name)) {
-		// if we searched every entry to no avail:
-		if ((hash_val = (hash_val + 1) & (HASHSIZE - 1)) == orig_hash_val)
-			goto test4;
-	}
-
-	goto got_one;
-
-test4:
-	hash_val = orig_hash_val;
-	while (!(_resources[hash_val].Flags & MARKED_PURGE))
-		// if we searched every entry to no avail:
-		if ((hash_val = (hash_val + 1) & (HASHSIZE - 1)) == orig_hash_val) {
-			error("Out of resource space");
+	if (_resources[hash_val].Flags) {
+		// Flags is set, so scan until Flags is clear, or the resource name strings match
+		while ((_resources[hash_val].Flags & FULLY_BUFFERED)
+				&& !resName.equals(_resources[hash_val].name)) {
+			// if we searched every entry to no avail:
+			if ((hash_val = (hash_val + 1) & (HASHSIZE - 1)) == orig_hash_val) {
+				hash_val = orig_hash_val;
+				while (!(_resources[hash_val].Flags & MARKED_PURGE))
+					// if we searched every entry to no avail:
+					if ((hash_val = (hash_val + 1) & (HASHSIZE - 1)) == orig_hash_val) {
+						error("Out of resource space");
+					}
+
+				res = &_resources[hash_val];
+				delete[] res->RHandle;
+				res->RHandle = nullptr;
+			}
 		}
+	}
 
-	res = &_resources[hash_val];
-	delete[] res->RHandle;
-	res->RHandle = nullptr;
-
-got_one:
 	res = &_resources[hash_val];
 	res->name = resName;
 	res->Flags = FULLY_BUFFERED;
@@ -96,12 +89,11 @@ int Resources::hash(const Common::String &sym) const {
 }
 
 MemHandle Resources::rget(const Common::String &resourceName, int32 *resourceSize) {
-	Entry *resEntry;
-
 	if (resourceSize)
 		*resourceSize = 0;
 
-	if (!(resEntry = findAndSetResEntry(resourceName))) {
+	Entry *resEntry = findAndSetResEntry(resourceName);
+	if (!resEntry) {
 		term_message("rget:%s  -> failed!", resourceName.c_str());
 		return nullptr;
 	}
@@ -152,13 +144,12 @@ MemHandle Resources::rget(const Common::String &resourceName, int32 *resourceSiz
 }
 
 void Resources::rtoss(const Common::String &resourceName) {
-	int hash_val;
 	Entry *resEntry = nullptr;
 	Common::String resName = resourceName;
 
 	if (_useLowercase)
 		resName.toLowercase();
-	hash_val = hash(resName);
+	int hash_val = hash(resName);
 
 	// Check if resource is in resource table
 	if (_resources[hash_val].Flags) {
@@ -173,7 +164,8 @@ void Resources::rtoss(const Common::String &resourceName) {
 
 	if (!resEntry)
 		error_show(FL, 'RIOU', "rtoss: %s", resourceName.c_str());
-	else if (!(resEntry->Flags & FULLY_BUFFERED))
+
+	if (!(resEntry->Flags & FULLY_BUFFERED))
 		return;
 
 	if (!resEntry || !*resEntry->RHandle) {




More information about the Scummvm-git-logs mailing list