Skip to content

Commit 6442be2

Browse files
authored
Use try_emplace to avoid multipe look-up (#538)
1 parent 27a26ed commit 6442be2

1 file changed

Lines changed: 2 additions & 4 deletions

File tree

include/CXXGraph/Partitioning/CoordinatedPartitionState.hpp

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -110,10 +110,8 @@ template <typename T>
110110
std::shared_ptr<Record<T>> CoordinatedPartitionState<T>::getRecord(
111111
CXXGraph::id_t x) {
112112
std::lock_guard<std::mutex> lock(*record_map_mutex);
113-
if (record_map.find(x) == record_map.end()) {
114-
record_map[x] = std::make_shared<CoordinatedRecord<T>>();
115-
}
116-
return record_map.at(x);
113+
return record_map.try_emplace(x, std::make_shared<CoordinatedRecord<T>>())
114+
.first->second;
117115
}
118116

119117
template <typename T>

0 commit comments

Comments
 (0)