aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAleksi Lindeman <0xdec05eba@gmail.com>2018-03-13 03:10:32 +0100
committerAleksi Lindeman <0xdec05eba@gmail.com>2018-03-13 03:11:43 +0100
commit70ad3928a93a175e52264b2776f57c76c82fa261 (patch)
tree3e2cdfc0d1fb1b65159dd7dc0ca3027896b4184d
parentf84aba861d26601ae4c7203daa39752e7c95cfd8 (diff)
Use result of set::insert to determinate if data already exists
Instead of using .find (::insert uses find)
-rw-r--r--src/DatabaseStorage.cpp10
1 files 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)