@@ -17,7 +17,7 @@ Author: Daniel Kroening, kroening@kroening.com
1717#include " string_hash.h"
1818#include " irep_hash.h"
1919
20- #ifdef SUB_IS_LIST
20+ #ifdef NAMED_SUB_IS_FORWARD_LIST
2121#include < algorithm>
2222#endif
2323
@@ -31,7 +31,7 @@ irept nil_rep_storage;
3131irept::dt irept::empty_d;
3232#endif
3333
34- #ifdef SUB_IS_LIST
34+ #ifdef NAMED_SUB_IS_FORWARD_LIST
3535static inline bool named_subt_order (
3636 const std::pair<irep_namet, irept> &a,
3737 const irep_namet &b)
@@ -152,9 +152,9 @@ void irept::nonrecursive_destructor(dt *old_data)
152152
153153 if (d->ref_count ==0 )
154154 {
155- stack.reserve (stack. size ()+
156- d->named_sub .size () +
157- d->sub .size ());
155+ stack.reserve (
156+ stack. size () + std::distance (d-> named_sub . begin (), d->named_sub .end ()) +
157+ d->sub .size ());
158158
159159 for (named_subt::iterator
160160 it=d->named_sub .begin ();
@@ -203,7 +203,7 @@ const irep_idt &irept::get(const irep_namet &name) const
203203{
204204 const named_subt &s = get_named_sub ();
205205
206- #ifdef SUB_IS_LIST
206+ #ifdef NAMED_SUB_IS_FORWARD_LIST
207207 named_subt::const_iterator it=named_subt_lower_bound (s, name);
208208
209209 if (it==s.end () ||
@@ -259,11 +259,16 @@ void irept::remove(const irep_namet &name)
259259{
260260 named_subt &s = get_named_sub ();
261261
262- #ifdef SUB_IS_LIST
262+ #ifdef NAMED_SUB_IS_FORWARD_LIST
263263 named_subt::iterator it=named_subt_lower_bound (s, name);
264264
265265 if (it!=s.end () && it->first ==name)
266- s.erase (it);
266+ {
267+ named_subt::iterator before = s.before_begin ();
268+ while (std::next (before) != it)
269+ ++before;
270+ s.erase_after (before);
271+ }
267272#else
268273 s.erase (name);
269274#endif
@@ -273,7 +278,7 @@ const irept &irept::find(const irep_namet &name) const
273278{
274279 const named_subt &s = get_named_sub ();
275280
276- #ifdef SUB_IS_LIST
281+ #ifdef NAMED_SUB_IS_FORWARD_LIST
277282 named_subt::const_iterator it=named_subt_lower_bound (s, name);
278283
279284 if (it==s.end () ||
@@ -293,12 +298,17 @@ irept &irept::add(const irep_namet &name)
293298{
294299 named_subt &s = get_named_sub ();
295300
296- #ifdef SUB_IS_LIST
301+ #ifdef NAMED_SUB_IS_FORWARD_LIST
297302 named_subt::iterator it=named_subt_lower_bound (s, name);
298303
299304 if (it==s.end () ||
300305 it->first !=name)
301- it=s.insert (it, std::make_pair (name, irept ()));
306+ {
307+ named_subt::iterator before = s.before_begin ();
308+ while (std::next (before) != it)
309+ ++before;
310+ it = s.emplace_after (before, name, irept ());
311+ }
302312
303313 return it->second ;
304314#else
@@ -310,12 +320,17 @@ irept &irept::add(const irep_namet &name, const irept &irep)
310320{
311321 named_subt &s = get_named_sub ();
312322
313- #ifdef SUB_IS_LIST
323+ #ifdef NAMED_SUB_IS_FORWARD_LIST
314324 named_subt::iterator it=named_subt_lower_bound (s, name);
315325
316326 if (it==s.end () ||
317327 it->first !=name)
318- it=s.insert (it, std::make_pair (name, irep));
328+ {
329+ named_subt::iterator before = s.before_begin ();
330+ while (std::next (before) != it)
331+ ++before;
332+ it = s.emplace_after (before, name, irep);
333+ }
319334 else
320335 it->second =irep;
321336
@@ -407,13 +422,24 @@ bool irept::full_eq(const irept &other) const
407422
408423 const irept::subt &i1_sub=get_sub ();
409424 const irept::subt &i2_sub=other.get_sub ();
425+
426+ if (i1_sub.size () != i2_sub.size ())
427+ return false ;
428+
410429 const irept::named_subt &i1_named_sub=get_named_sub ();
411430 const irept::named_subt &i2_named_sub=other.get_named_sub ();
412431
432+ #ifdef NAMED_SUB_IS_FORWARD_LIST
413433 if (
414- i1_sub.size () != i2_sub.size () ||
415- i1_named_sub.size () != i2_named_sub.size ())
434+ std::distance (i1_named_sub.begin (), i1_named_sub.end ()) !=
435+ std::distance (i2_named_sub.begin (), i2_named_sub.end ()))
436+ {
437+ return false ;
438+ }
439+ #else
440+ if (i1_named_sub.size () != i2_named_sub.size ())
416441 return false ;
442+ #endif
417443
418444 for (std::size_t i=0 ; i<i1_sub.size (); i++)
419445 if (!i1_sub[i].full_eq (i2_sub[i]))
@@ -667,7 +693,13 @@ std::size_t irept::full_hash() const
667693 result=hash_combine (result, it->second .full_hash ());
668694 }
669695
670- result = hash_finalize (result, named_sub.size () + sub.size ());
696+ #ifdef NAMED_SUB_IS_FORWARD_LIST
697+ const std::size_t named_sub_size =
698+ std::distance (named_sub.begin (), named_sub.end ());
699+ #else
700+ const std::size_t named_sub_size = named_sub.size ();
701+ #endif
702+ result = hash_finalize (result, named_sub_size + sub.size ());
671703
672704 return result;
673705}
0 commit comments