[Scummvm-git-logs] scummvm master -> b5804e12576046215eae2c494355413748b37efd
criezy
criezy at scummvm.org
Sat Apr 3 01:10:01 UTC 2021
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:
b5804e1257 COMMON: Do not return an error for unknown hashmap key in release builds
Commit: b5804e12576046215eae2c494355413748b37efd
https://github.com/scummvm/scummvm/commit/b5804e12576046215eae2c494355413748b37efd
Author: Thierry Crozat (criezy at scummvm.org)
Date: 2021-04-03T02:09:53+01:00
Commit Message:
COMMON: Do not return an error for unknown hashmap key in release builds
We have a lot of legacy code that was written with the old behaviour
where it returned the default value in such a case. Until we are
confident all this code has been updated, we continue to use the
old behaviour in release builds to avoid creating instabilities.
This still error our in non-release builds, which will help detect
the code that still needs to be updated.
Changed paths:
common/hashmap.h
diff --git a/common/hashmap.h b/common/hashmap.h
index 848e600fbb..6a63cd0345 100644
--- a/common/hashmap.h
+++ b/common/hashmap.h
@@ -638,7 +638,17 @@ Val &HashMap<Key, Val, HashFunc, EqualFunc>::getVal(const Key &key) {
if (_storage[ctr] != nullptr)
return _storage[ctr]->_value;
else
+ // In the past getVal() and operator[] used to return the default value for this case.
+ // Clarifying the intent by using getValOrDefault() when we query a key that may not be
+ // present is a good idea, but we have a lot of legacy code that may need to be updated.
+ // So for now only returns an error in non-release builds. Once we are confident all the
+ // code has been updated to use the correct function we can remove the RELEASE_BUILD
+ // special case.
+#ifdef RELEASE_BUILD
+ return _defaultVal;
+#else
unknownKeyError(key);
+#endif
}
template<class Key, class Val, class HashFunc, class EqualFunc>
@@ -647,7 +657,12 @@ const Val &HashMap<Key, Val, HashFunc, EqualFunc>::getVal(const Key &key) const
if (_storage[ctr] != nullptr)
return _storage[ctr]->_value;
else
+ // See comment in non-const getVal() above.
+#ifdef RELEASE_BUILD
+ return _defaultVal;
+#else
unknownKeyError(key);
+#endif
}
template<class Key, class Val, class HashFunc, class EqualFunc>
More information about the Scummvm-git-logs
mailing list