17
17
#include " string_hash.h"
18
18
#include " irep_hash.h"
19
19
20
- #ifdef SUB_IS_LIST
20
+ #ifdef NAMED_SUB_IS_FORWARD_LIST
21
21
#include < algorithm>
22
22
#endif
23
23
@@ -31,7 +31,7 @@ irept nil_rep_storage;
31
31
irept::dt irept::empty_d;
32
32
#endif
33
33
34
- #ifdef SUB_IS_LIST
34
+ #ifdef NAMED_SUB_IS_FORWARD_LIST
35
35
static inline bool named_subt_order (
36
36
const std::pair<irep_namet, irept> &a,
37
37
const irep_namet &b)
@@ -152,9 +152,9 @@ void irept::nonrecursive_destructor(dt *old_data)
152
152
153
153
if (d->ref_count ==0 )
154
154
{
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 ());
158
158
159
159
for (named_subt::iterator
160
160
it=d->named_sub .begin ();
@@ -203,7 +203,7 @@ const irep_idt &irept::get(const irep_namet &name) const
203
203
{
204
204
const named_subt &s = get_named_sub ();
205
205
206
- #ifdef SUB_IS_LIST
206
+ #ifdef NAMED_SUB_IS_FORWARD_LIST
207
207
named_subt::const_iterator it=named_subt_lower_bound (s, name);
208
208
209
209
if (it==s.end () ||
@@ -259,11 +259,16 @@ void irept::remove(const irep_namet &name)
259
259
{
260
260
named_subt &s = get_named_sub ();
261
261
262
- #ifdef SUB_IS_LIST
262
+ #ifdef NAMED_SUB_IS_FORWARD_LIST
263
263
named_subt::iterator it=named_subt_lower_bound (s, name);
264
264
265
265
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
+ }
267
272
#else
268
273
s.erase (name);
269
274
#endif
@@ -273,7 +278,7 @@ const irept &irept::find(const irep_namet &name) const
273
278
{
274
279
const named_subt &s = get_named_sub ();
275
280
276
- #ifdef SUB_IS_LIST
281
+ #ifdef NAMED_SUB_IS_FORWARD_LIST
277
282
named_subt::const_iterator it=named_subt_lower_bound (s, name);
278
283
279
284
if (it==s.end () ||
@@ -293,12 +298,17 @@ irept &irept::add(const irep_namet &name)
293
298
{
294
299
named_subt &s = get_named_sub ();
295
300
296
- #ifdef SUB_IS_LIST
301
+ #ifdef NAMED_SUB_IS_FORWARD_LIST
297
302
named_subt::iterator it=named_subt_lower_bound (s, name);
298
303
299
304
if (it==s.end () ||
300
305
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
+ }
302
312
303
313
return it->second ;
304
314
#else
@@ -310,12 +320,17 @@ irept &irept::add(const irep_namet &name, const irept &irep)
310
320
{
311
321
named_subt &s = get_named_sub ();
312
322
313
- #ifdef SUB_IS_LIST
323
+ #ifdef NAMED_SUB_IS_FORWARD_LIST
314
324
named_subt::iterator it=named_subt_lower_bound (s, name);
315
325
316
326
if (it==s.end () ||
317
327
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
+ }
319
334
else
320
335
it->second =irep;
321
336
@@ -407,13 +422,24 @@ bool irept::full_eq(const irept &other) const
407
422
408
423
const irept::subt &i1_sub=get_sub ();
409
424
const irept::subt &i2_sub=other.get_sub ();
425
+
426
+ if (i1_sub.size () != i2_sub.size ())
427
+ return false ;
428
+
410
429
const irept::named_subt &i1_named_sub=get_named_sub ();
411
430
const irept::named_subt &i2_named_sub=other.get_named_sub ();
412
431
432
+ #ifdef NAMED_SUB_IS_FORWARD_LIST
413
433
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 ())
416
441
return false ;
442
+ #endif
417
443
418
444
for (std::size_t i=0 ; i<i1_sub.size (); i++)
419
445
if (!i1_sub[i].full_eq (i2_sub[i]))
@@ -667,7 +693,13 @@ std::size_t irept::full_hash() const
667
693
result=hash_combine (result, it->second .full_hash ());
668
694
}
669
695
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 ());
671
703
672
704
return result;
673
705
}
0 commit comments