diff --git a/include/loki/details/utils/segmented_repository.hpp b/include/loki/details/utils/segmented_repository.hpp index 08a84df..3830efc 100644 --- a/include/loki/details/utils/segmented_repository.hpp +++ b/include/loki/details/utils/segmented_repository.hpp @@ -76,29 +76,29 @@ class SegmentedRepository size_t index = m_uniqueness_set.size(); assert(index == m_persistent_vector.size()); - // Explicitly call the constructor of T to give exclusive access to the factory. - auto element_ptr = ObserverPtr(&m_persistent_vector.emplace_back(T(index, std::forward(args)...))); - // The pointer to the location in persistent memory. - assert(element_ptr); + // Create element of type T + auto element = T(index, std::forward(args)...); /* Test for uniqueness */ - auto it = m_uniqueness_set.find(element_ptr); + auto it = m_uniqueness_set.find(ObserverPtr(&element)); if (it == m_uniqueness_set.end()) { /* Element is unique! */ - m_uniqueness_set.emplace(element_ptr); - } - else - { - /* Element is not unique! */ + // Copy element to persistent memory + m_persistent_vector.push_back(std::move(element)); + + // Fetch the pointer to persistent element; + const auto persistent_addr = &m_persistent_vector.back(); + + // Mark the element as not unique. + m_uniqueness_set.insert(persistent_addr); - element_ptr = *it; - // Remove duplicate from vector - m_persistent_vector.pop_back(); + // Return pointer to persistent element. + return persistent_addr; } - return element_ptr.get(); + return it->get(); } /** diff --git a/include/loki/details/utils/segmented_vector.hpp b/include/loki/details/utils/segmented_vector.hpp index 73a9343..dbf2bd8 100644 --- a/include/loki/details/utils/segmented_vector.hpp +++ b/include/loki/details/utils/segmented_vector.hpp @@ -115,15 +115,6 @@ class SegmentedVector return element; } - void pop_back() - { - assert(m_size > 0); - auto& segment = m_segments.back(); - segment.pop_back(); - m_accessor.pop_back(); - --m_size; - } - /** * Accessors */