From 82025735c3f4f125adce205837c3953b6a44cf78 Mon Sep 17 00:00:00 2001 From: dec05eba Date: Tue, 13 Mar 2018 03:10:32 +0100 Subject: Use result of set::insert to determinate if data already exists Instead of using .find (::insert uses find) --- src/DatabaseStorage.cpp | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/src/DatabaseStorage.cpp b/src/DatabaseStorage.cpp index 0f75d1f..5e43d1a 100644 --- a/src/DatabaseStorage.cpp +++ b/src/DatabaseStorage.cpp @@ -58,8 +58,8 @@ namespace odhtdb throw DatabaseStorageNotFound(errMsg); } - auto storedDataIt = storedDataHash.find(dataHash); - if(storedDataIt != storedDataHash.end()) + auto storeDataHashResult = storedDataHash.insert(dataHash); + if(!storeDataHashResult.second) { string errMsg = "Database already contains data with hash: "; errMsg += dataHash.toString(); @@ -70,13 +70,12 @@ namespace odhtdb memcpy(storageData.data, data, dataSize); DatabaseStorageObject *databaseStorageObject = new DatabaseStorageObject(storageData, timestamp, creatorUser->getPublicKey()); it->second->objects.push_back(databaseStorageObject); - storedDataHash.insert(dataHash); } void DatabaseStorage::addToQuarantine(const Hash &dataHash, const Signature::PublicKey &creatorPublicKey, u64 timestamp, const u8 *data, usize dataSize) { - auto storedDataIt = storedDataHash.find(dataHash); - if(storedDataIt != storedDataHash.end()) + auto storeDataHashResult = storedDataHash.insert(dataHash); + if(!storeDataHashResult.second) { string errMsg = "Database already contains data with hash: "; errMsg += dataHash.toString(); @@ -87,7 +86,6 @@ namespace odhtdb memcpy(storageData.data, data, dataSize); DatabaseStorageQuarantineObject *databaseQuarantineStorageObject = new DatabaseStorageQuarantineObject(storageData, timestamp, creatorPublicKey); quarantineStorageMap[creatorPublicKey].emplace_back(databaseQuarantineStorageObject); - storedDataHash.insert(dataHash); } void DatabaseStorage::addUser(User *user, const Hash &hash) -- cgit v1.2.3