Skip to content

Commit a80a8df

Browse files
refactor: optimize GetOrAdd method in signing_shares.h
Replaced the previous implementation of the GetOrAdd method with a more efficient approach using emplace. This change simplifies the logic by directly attempting to insert a new entry into the internal map, improving performance and readability while maintaining the same functionality.
1 parent ae2dc7a commit a80a8df

File tree

1 file changed

+3
-6
lines changed

1 file changed

+3
-6
lines changed

src/llmq/signing_shares.h

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -210,12 +210,9 @@ class SigShareMap
210210

211211
T& GetOrAdd(const SigShareKey& k)
212212
{
213-
T* v = Get(k);
214-
if (!v) {
215-
Add(k, T());
216-
v = Get(k);
217-
}
218-
return *v;
213+
auto& m = internalMap[k.first]; // Get or create outer map entry
214+
auto result = m.emplace(k.second, T()); // Try to insert, returns pair<iterator, bool>
215+
return result.first->second; // Return reference to the value (new or existing)
219216
}
220217

221218
const T* GetFirst() const

0 commit comments

Comments
 (0)