@@ -154,7 +154,6 @@ void irept::nonrecursive_destructor(dt *old_data)
154154 {
155155 stack.reserve (stack.size ()+
156156 d->named_sub .size ()+
157- d->comments .size ()+
158157 d->sub .size ());
159158
160159 for (named_subt::iterator
@@ -166,15 +165,6 @@ void irept::nonrecursive_destructor(dt *old_data)
166165 it->second .data =&empty_d;
167166 }
168167
169- for (named_subt::iterator
170- it=d->comments .begin ();
171- it!=d->comments .end ();
172- it++)
173- {
174- stack.push_back (it->second .data );
175- it->second .data =&empty_d;
176- }
177-
178168 for (subt::iterator
179169 it=d->sub .begin ();
180170 it!=d->sub .end ();
@@ -211,10 +201,9 @@ void irept::move_to_sub(irept &irep)
211201
212202const irep_idt &irept::get (const irep_namet &name) const
213203{
214- const named_subt &s=
215- is_comment (name)?get_comments ():get_named_sub ();
204+ const named_subt &s = get_named_sub ();
216205
217- #ifdef SUB_IS_LIST
206+ #ifdef SUB_IS_LIST
218207 named_subt::const_iterator it=named_subt_lower_bound (s, name);
219208
220209 if (it==s.end () ||
@@ -223,15 +212,15 @@ const irep_idt &irept::get(const irep_namet &name) const
223212 static const irep_idt empty;
224213 return empty;
225214 }
226- #else
215+ #else
227216 named_subt::const_iterator it=s.find (name);
228217
229218 if (it==s.end ())
230219 {
231220 static const irep_idt empty;
232221 return empty;
233222 }
234- #endif
223+ #endif
235224
236225 return it->second .id ();
237226}
@@ -268,64 +257,60 @@ void irept::set(const irep_namet &name, const long long value)
268257
269258void irept::remove (const irep_namet &name)
270259{
271- named_subt &s=
272- is_comment (name)?get_comments ():get_named_sub ();
260+ named_subt &s = get_named_sub ();
273261
274- #ifdef SUB_IS_LIST
262+ #ifdef SUB_IS_LIST
275263 named_subt::iterator it=named_subt_lower_bound (s, name);
276264
277265 if (it!=s.end () && it->first ==name)
278266 s.erase (it);
279- #else
267+ #else
280268 s.erase (name);
281- #endif
269+ #endif
282270}
283271
284272const irept &irept::find (const irep_namet &name) const
285273{
286- const named_subt &s=
287- is_comment (name)?get_comments ():get_named_sub ();
274+ const named_subt &s = get_named_sub ();
288275
289- #ifdef SUB_IS_LIST
276+ #ifdef SUB_IS_LIST
290277 named_subt::const_iterator it=named_subt_lower_bound (s, name);
291278
292279 if (it==s.end () ||
293280 it->first !=name)
294281 return get_nil_irep ();
295- #else
282+ #else
296283 named_subt::const_iterator it=s.find (name);
297284
298285 if (it==s.end ())
299286 return get_nil_irep ();
300- #endif
287+ #endif
301288
302289 return it->second ;
303290}
304291
305292irept &irept::add (const irep_namet &name)
306293{
307- named_subt &s=
308- is_comment (name)?get_comments ():get_named_sub ();
294+ named_subt &s = get_named_sub ();
309295
310- #ifdef SUB_IS_LIST
296+ #ifdef SUB_IS_LIST
311297 named_subt::iterator it=named_subt_lower_bound (s, name);
312298
313299 if (it==s.end () ||
314300 it->first !=name)
315301 it=s.insert (it, std::make_pair (name, irept ()));
316302
317303 return it->second ;
318- #else
304+ #else
319305 return s[name];
320- #endif
306+ #endif
321307}
322308
323309irept &irept::add (const irep_namet &name, const irept &irep)
324310{
325- named_subt &s=
326- is_comment (name)?get_comments ():get_named_sub ();
311+ named_subt &s = get_named_sub ();
327312
328- #ifdef SUB_IS_LIST
313+ #ifdef SUB_IS_LIST
329314 named_subt::iterator it=named_subt_lower_bound (s, name);
330315
331316 if (it==s.end () ||
@@ -335,15 +320,15 @@ irept &irept::add(const irep_namet &name, const irept &irep)
335320 it->second =irep;
336321
337322 return it->second ;
338- #else
323+ #else
339324 std::pair<named_subt::iterator, bool > entry=
340325 s.insert (std::make_pair (name, irep));
341326
342327 if (!entry.second )
343328 entry.first ->second =irep;
344329
345330 return entry.first ->second ;
346- #endif
331+ #endif
347332}
348333
349334#ifdef IREP_HASH_STATS
@@ -361,18 +346,52 @@ bool irept::operator==(const irept &other) const
361346 return true ;
362347 #endif
363348
364- if (id ()!=other.id () ||
365- get_sub ()!=other.get_sub () || // recursive call
366- get_named_sub ()!=other.get_named_sub ()) // recursive call
349+ if (id () != other.id () || get_sub () != other.get_sub ()) // recursive call
367350 {
368351 #ifdef IREP_HASH_STATS
369352 ++irep_cmp_ne_cnt;
370353 #endif
371354 return false ;
372355 }
373356
374- // comments are NOT checked
357+ const auto &this_named_sub = get_named_sub ();
358+ const auto &other_named_sub = other.get_named_sub ();
359+
360+ // walk in sync, ignoring comments, until end of both maps
361+ named_subt::const_iterator this_it = this_named_sub.begin ();
362+ named_subt::const_iterator other_it = other_named_sub.begin ();
363+
364+ while (this_it != this_named_sub.end () || other_it != other_named_sub.end ())
365+ {
366+ if (this_it != this_named_sub.end () && is_comment (this_it->first ))
367+ {
368+ this_it++;
369+ continue ;
370+ }
371+
372+ if (other_it != other_named_sub.end () && is_comment (other_it->first ))
373+ {
374+ other_it++;
375+ continue ;
376+ }
377+
378+ if (
379+ this_it == this_named_sub.end () || // reached end of 'this'
380+ other_it == other_named_sub.end () || // reached the end of 'other'
381+ this_it->first != other_it->first ||
382+ this_it->second != other_it->second ) // recursive call
383+ {
384+ #ifdef IREP_HASH_STATS
385+ ++irep_cmp_ne_cnt;
386+ #endif
387+ return false ;
388+ }
375389
390+ this_it++;
391+ other_it++;
392+ }
393+
394+ // reached the end of both
376395 return true ;
377396}
378397
@@ -390,12 +409,10 @@ bool irept::full_eq(const irept &other) const
390409 const irept::subt &i2_sub=other.get_sub ();
391410 const irept::named_subt &i1_named_sub=get_named_sub ();
392411 const irept::named_subt &i2_named_sub=other.get_named_sub ();
393- const irept::named_subt &i1_comments=get_comments ();
394- const irept::named_subt &i2_comments=other.get_comments ();
395412
396- if (i1_sub. size ()!=i2_sub. size () ||
397- i1_named_sub .size ()!=i2_named_sub .size () ||
398- i1_comments .size ()!=i2_comments .size ())
413+ if (
414+ i1_sub .size () != i2_sub .size () ||
415+ i1_named_sub .size () != i2_named_sub .size ())
399416 return false ;
400417
401418 for (std::size_t i=0 ; i<i1_sub.size (); i++)
@@ -412,16 +429,6 @@ bool irept::full_eq(const irept &other) const
412429 return false ;
413430 }
414431
415- {
416- irept::named_subt::const_iterator i1_it=i1_comments.begin ();
417- irept::named_subt::const_iterator i2_it=i2_comments.begin ();
418-
419- for (; i1_it!=i1_comments.end (); i1_it++, i2_it++)
420- if (i1_it->first !=i2_it->first ||
421- !i1_it->second .full_eq (i2_it->second ))
422- return false ;
423- }
424-
425432 return true ;
426433}
427434
@@ -606,7 +613,6 @@ std::size_t irept::full_hash() const
606613{
607614 const irept::subt &sub=get_sub ();
608615 const irept::named_subt &named_sub=get_named_sub ();
609- const irept::named_subt &comments=get_comments ();
610616
611617 std::size_t result=hash_string (id ());
612618
@@ -618,15 +624,7 @@ std::size_t irept::full_hash() const
618624 result=hash_combine (result, it->second .full_hash ());
619625 }
620626
621- forall_named_irep (it, comments)
622- {
623- result=hash_combine (result, hash_string (it->first ));
624- result=hash_combine (result, it->second .full_hash ());
625- }
626-
627- result=hash_finalize (
628- result,
629- named_sub.size ()+sub.size ()+comments.size ());
627+ result = hash_finalize (result, named_sub.size () + sub.size ());
630628
631629 return result;
632630}
@@ -662,18 +660,6 @@ std::string irept::pretty(unsigned indent, unsigned max_indent) const
662660 result+=it->second .pretty (indent+2 , max_indent);
663661 }
664662
665- forall_named_irep (it, get_comments ())
666- {
667- result+=" \n " ;
668- indent_str (result, indent);
669-
670- result+=" * " ;
671- result+=id2string (it->first );
672- result+=" : " ;
673-
674- result+=it->second .pretty (indent+2 , max_indent);
675- }
676-
677663 std::size_t count=0 ;
678664
679665 forall_irep (it, get_sub ())
0 commit comments