aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authordec05eba <dec05eba@protonmail.com>2018-03-13 03:10:32 +0100
committerdec05eba <dec05eba@protonmail.com>2020-08-18 23:25:46 +0200
commit82025735c3f4f125adce205837c3953b6a44cf78 (patch)
tree144387e205855d345cfb2944956c51faebcef3f0 /src
parentc7740f0e3cbcd9a7233258f22e6168b1cd8853a8 (diff)
Use result of set::insert to determinate if data already exists
Instead of using .find (::insert uses find)
Diffstat (limited to 'src')
-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)