Only hash key once if key not found, i.e. use [] instead of find() and then emplace()

This commit is contained in:
Sebastian Messmer 2016-06-21 23:43:52 -07:00
parent 389273a24f
commit adb10343d2

View File

@ -34,17 +34,12 @@ KnownBlockVersions::~KnownBlockVersions() {
bool KnownBlockVersions::checkAndUpdateVersion(const Key &key, uint64_t version) {
ASSERT(_valid, "Object not valid due to a std::move");
auto found = _knownVersions.find(key);
if (found == _knownVersions.end()) {
_knownVersions.emplace(key, version);
return true;
}
if (found->second > version) {
uint64_t &found = _knownVersions[key]; // If the entry doesn't exist, this creates it with value 0.
if (found > version) {
return false;
}
found->second = version;
found = version;
return true;
}