@@ -28,7 +28,13 @@ std::size_t to_be_merged_irept::hash() const
2828 result, static_cast <const merged_irept &>(it->second ).hash ());
2929 }
3030
31- result=hash_finalize (result, named_sub.size ()+sub.size ());
31+ #ifdef SUB_IS_LIST
32+ const std::size_t named_sub_size =
33+ std::distance (named_sub.begin (), named_sub.end ());
34+ #else
35+ const std::size_t named_sub_size = named_sub.size ();
36+ #endif
37+ result = hash_finalize (result, named_sub_size + sub.size ());
3238
3339 return result;
3440}
@@ -44,9 +50,16 @@ bool to_be_merged_irept::operator == (const to_be_merged_irept &other) const
4450 const irept::named_subt &o_named_sub=other.get_named_sub ();
4551
4652 if (sub.size ()!=o_sub.size ())
47- return true ;
53+ return false ;
54+ #ifdef SUB_IS_LIST
55+ if (
56+ std::distance (named_sub.begin (), named_sub.end ()) !=
57+ std::distance (o_named_sub.begin (), o_named_sub.end ()))
58+ return false ;
59+ #else
4860 if (named_sub.size ()!=o_named_sub.size ())
49- return true ;
61+ return false ;
62+ #endif
5063
5164 {
5265 irept::subt::const_iterator s_it=sub.begin ();
@@ -95,13 +108,19 @@ const merged_irept &merged_irepst::merged(const irept &irep)
95108 const irept::named_subt &src_named_sub=irep.get_named_sub ();
96109 irept::named_subt &dest_named_sub=new_irep.get_named_sub ();
97110
111+ #ifdef SUB_IS_LIST
112+ irept::named_subt::iterator before = dest_named_sub.before_begin ();
113+ #endif
98114 forall_named_irep (it, src_named_sub)
115+ {
99116 #ifdef SUB_IS_LIST
100- dest_named_sub.push_back (
101- std::make_pair (it->first , merged (it->second ))); // recursive call
117+ dest_named_sub.emplace_after (
118+ before, it->first , merged (it->second )); // recursive call
119+ ++before;
102120 #else
103121 dest_named_sub[it->first ]=merged (it->second ); // recursive call
104122 #endif
123+ }
105124
106125 std::pair<to_be_merged_irep_storet::const_iterator, bool > result=
107126 to_be_merged_irep_store.insert (to_be_merged_irept (new_irep));
@@ -140,24 +159,36 @@ const irept &merge_irept::merged(const irept &irep)
140159 const irept::named_subt &src_named_sub=irep.get_named_sub ();
141160 irept::named_subt &dest_named_sub=new_irep.get_named_sub ();
142161
162+ #ifdef SUB_IS_LIST
163+ irept::named_subt::iterator before = dest_named_sub.before_begin ();
164+ #endif
143165 forall_named_irep (it, src_named_sub)
166+ {
144167 #ifdef SUB_IS_LIST
145- dest_named_sub.push_back (
146- std::make_pair (it->first , merged (it->second ))); // recursive call
168+ dest_named_sub.emplace_after (
169+ before, it->first , merged (it->second )); // recursive call
170+ ++before;
147171 #else
148172 dest_named_sub[it->first ]=merged (it->second ); // recursive call
149173 #endif
174+ }
150175
151176 const irept::named_subt &src_comments=irep.get_comments ();
152177 irept::named_subt &dest_comments=new_irep.get_comments ();
153178
179+ #ifdef SUB_IS_LIST
180+ before = dest_comments.before_begin ();
181+ #endif
154182 forall_named_irep (it, src_comments)
183+ {
155184 #ifdef SUB_IS_LIST
156- dest_comments.push_back (
157- std::make_pair (it->first , merged (it->second ))); // recursive call
185+ dest_comments.emplace_after (
186+ before, it->first , merged (it->second )); // recursive call
187+ ++before;
158188 #else
159189 dest_comments[it->first ]=merged (it->second ); // recursive call
160190 #endif
191+ }
161192
162193 return *irep_store.insert (new_irep).first ;
163194}
@@ -188,24 +219,36 @@ const irept &merge_full_irept::merged(const irept &irep)
188219 const irept::named_subt &src_named_sub=irep.get_named_sub ();
189220 irept::named_subt &dest_named_sub=new_irep.get_named_sub ();
190221
222+ #ifdef SUB_IS_LIST
223+ irept::named_subt::iterator before = dest_named_sub.before_begin ();
224+ #endif
191225 forall_named_irep (it, src_named_sub)
226+ {
192227 #ifdef SUB_IS_LIST
193- dest_named_sub.push_back (
194- std::make_pair (it->first , merged (it->second ))); // recursive call
228+ dest_named_sub.emplace_after (
229+ before, it->first , merged (it->second )); // recursive call
230+ ++before;
195231 #else
196232 dest_named_sub[it->first ]=merged (it->second ); // recursive call
197233 #endif
234+ }
198235
199236 const irept::named_subt &src_comments=irep.get_comments ();
200237 irept::named_subt &dest_comments=new_irep.get_comments ();
201238
239+ #ifdef SUB_IS_LIST
240+ before = dest_comments.before_begin ();
241+ #endif
202242 forall_named_irep (it, src_comments)
243+ {
203244 #ifdef SUB_IS_LIST
204- dest_comments.push_back (
205- std::make_pair (it->first , merged (it->second ))); // recursive call
245+ dest_comments.emplace_after (
246+ before, it->first , merged (it->second )); // recursive call
247+ ++before;
206248 #else
207249 dest_comments[it->first ]=merged (it->second ); // recursive call
208250 #endif
251+ }
209252
210253 return *irep_store.insert (new_irep).first ;
211254}
0 commit comments