@@ -145,37 +145,47 @@ void merge_irept::operator()(irept &irep)
145
145
146
146
const irept &merge_irept::merged (const irept &irep)
147
147
{
148
- irep_storet::const_iterator entry=irep_store.find (irep);
149
- if (entry!=irep_store.end ())
150
- return *entry;
151
-
152
- irept new_irep (irep.id ());
148
+ auto entry = irep_store.insert (irep);
149
+ if (!entry.second )
150
+ return *entry.first ;
153
151
154
152
const irept::subt &src_sub=irep.get_sub ();
155
- irept::subt &dest_sub=new_irep.get_sub ();
156
- dest_sub.reserve (src_sub.size ());
153
+ irept::subt *dest_sub_ptr = nullptr ;
157
154
155
+ std::size_t index = 0 ;
158
156
forall_irep (it, src_sub)
159
- dest_sub.push_back (merged (*it)); // recursive call
157
+ {
158
+ const irept &op = merged (*it); // recursive call
159
+ if (&op.read () != &(it->read ()))
160
+ {
161
+ if (!dest_sub_ptr)
162
+ dest_sub_ptr = &(const_cast <irept &>(*entry.first )).get_sub ();
163
+ (*dest_sub_ptr)[index ] = op;
164
+ }
165
+ ++index ;
166
+ }
160
167
161
168
const irept::named_subt &src_named_sub=irep.get_named_sub ();
162
- irept::named_subt &dest_named_sub=new_irep. get_named_sub () ;
169
+ irept::named_subt *dest_named_sub_ptr = nullptr ;
163
170
164
- #ifdef NAMED_SUB_IS_FORWARD_LIST
165
- irept::named_subt::iterator before = dest_named_sub.before_begin ();
166
- #endif
171
+ std::ptrdiff_t advance_by = 0 ;
167
172
forall_named_irep (it, src_named_sub)
168
173
{
169
- #ifdef NAMED_SUB_IS_FORWARD_LIST
170
- dest_named_sub.emplace_after (
171
- before, it->first , merged (it->second )); // recursive call
172
- ++before;
173
- #else
174
- dest_named_sub[it->first ]=merged (it->second ); // recursive call
175
- #endif
174
+ if (!irept::is_comment (it->first ))
175
+ {
176
+ const irept &op = merged (it->second ); // recursive call
177
+ if (&op.read () != &(it->second .read ()))
178
+ {
179
+ if (!dest_named_sub_ptr)
180
+ dest_named_sub_ptr =
181
+ &(const_cast <irept &>(*entry.first )).get_named_sub ();
182
+ std::next (dest_named_sub_ptr->begin (), advance_by)->second = op;
183
+ }
184
+ }
185
+ ++advance_by;
176
186
}
177
187
178
- return *irep_store. insert ( std::move (new_irep)) .first ;
188
+ return *entry .first ;
179
189
}
180
190
181
191
void merge_full_irept::operator ()(irept &irep)
0 commit comments