mirror of
https://github.com/libretro/scummvm.git
synced 2025-01-22 01:57:16 +00:00
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.
This commit is contained in:
parent
89dfb29454
commit
b5804e1257
@ -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>
|
||||
|
Loading…
x
Reference in New Issue
Block a user