@@ -70,58 +70,25 @@ struct NODISCARD ImmOrderedSet final
7070public:
7171 void erase (const Type id)
7272 {
73- auto it = std::lower_bound (m_vector.begin (), m_vector.end (), id);
73+ const auto it = std::lower_bound (m_vector.begin (), m_vector.end (), id);
7474 if (it != m_vector.end () && *it == id) {
75- size_t index = static_cast <size_t >(std::distance (m_vector.begin (), it));
76- m_vector = m_vector.erase (index);
75+ const auto index = static_cast <size_t >(std::distance (m_vector.begin (), it));
76+ m_vector = std::move ( m_vector) .erase (index);
7777 }
7878 }
7979
8080 void insert (const Type id)
8181 {
82- auto it = std::lower_bound (m_vector.begin (), m_vector.end (), id);
82+ const auto it = std::lower_bound (m_vector.begin (), m_vector.end (), id);
8383 if (it != m_vector.end () && *it == id) {
8484 return ;
8585 }
86- size_t index = static_cast <size_t >(std::distance (m_vector.begin (), it));
86+ const auto index = static_cast <size_t >(std::distance (m_vector.begin (), it));
8787 if (index == m_vector.size ()) {
88- m_vector = m_vector.push_back (id);
88+ m_vector = std::move ( m_vector) .push_back (id);
8989 return ;
9090 }
91- m_vector = m_vector.insert (index, id);
92- }
93-
94- public:
95- void insertAll (const ImmOrderedSet &other)
96- {
97- if (other.empty () || this == &other) {
98- return ;
99- }
100-
101- auto transient = typename Vector::transient_type{};
102-
103- auto this_it = this ->begin ();
104- const auto this_end = this ->end ();
105- auto other_it = other.begin ();
106- const auto other_end = other.end ();
107-
108- // Perform a sorted merge, adding unique elements from both vectors.
109- while (this_it != this_end && other_it != other_end) {
110- if (*this_it < *other_it) {
111- transient.push_back (*this_it++);
112- } else if (*other_it < *this_it) {
113- transient.push_back (*other_it++);
114- } else {
115- transient.push_back (*this_it++);
116- ++other_it;
117- }
118- }
119-
120- // Append any remaining elements from whichever vector was not fully consumed.
121- immer::copy (this_it, this_end, std::back_inserter (transient));
122- immer::copy (other_it, other_end, std::back_inserter (transient));
123-
124- m_vector = transient.persistent ();
91+ m_vector = std::move (m_vector).insert (index, id);
12592 }
12693
12794public:
0 commit comments