Skip to content

Commit e71ca91

Browse files
Make increase_counter take iterator
Taking an iterator instead of an identifier removes the need for a precondition (thus avoiding a lookup) and can avoid an additional lookup.
1 parent ba561d0 commit e71ca91

File tree

5 files changed

+25
-18
lines changed

5 files changed

+25
-18
lines changed

src/goto-symex/goto_symex_state.cpp

+11-6
Original file line numberDiff line numberDiff line change
@@ -185,8 +185,9 @@ void goto_symex_statet::assignment(
185185
#endif
186186

187187
// do the l2 renaming
188-
level2.current_names.emplace(l1_identifier, std::make_pair(lhs, 0));
189-
level2.increase_counter(l1_identifier);
188+
const auto level2_it =
189+
level2.current_names.emplace(l1_identifier, std::make_pair(lhs, 0)).first;
190+
symex_renaming_levelt::increase_counter(level2_it);
190191
set_l2_indices(lhs, ns);
191192

192193
// in case we happen to be multi-threaded, record the memory access
@@ -439,8 +440,10 @@ bool goto_symex_statet::l2_thread_read_encoding(
439440

440441
if(a_s_read.second.empty())
441442
{
442-
level2.current_names.emplace(l1_identifier, std::make_pair(ssa_l1, 0));
443-
level2.increase_counter(l1_identifier);
443+
auto level2_it =
444+
level2.current_names.emplace(l1_identifier, std::make_pair(ssa_l1, 0))
445+
.first;
446+
symex_renaming_levelt::increase_counter(level2_it);
444447
a_s_read.first=level2.current_count(l1_identifier);
445448
}
446449

@@ -476,7 +479,9 @@ bool goto_symex_statet::l2_thread_read_encoding(
476479
return true;
477480
}
478481

479-
level2.current_names.emplace(l1_identifier, std::make_pair(ssa_l1, 0));
482+
const auto level2_it =
483+
level2.current_names.emplace(l1_identifier, std::make_pair(ssa_l1, 0))
484+
.first;
480485

481486
// No event and no fresh index, but avoid constant propagation
482487
if(!record_events)
@@ -487,7 +492,7 @@ bool goto_symex_statet::l2_thread_read_encoding(
487492
}
488493

489494
// produce a fresh L2 name
490-
level2.increase_counter(l1_identifier);
495+
symex_renaming_levelt::increase_counter(level2_it);
491496
set_l2_indices(ssa_l1, ns);
492497
expr=ssa_l1;
493498

src/goto-symex/renaming_level.h

+2-3
Original file line numberDiff line numberDiff line change
@@ -38,10 +38,9 @@ struct symex_renaming_levelt
3838
}
3939

4040
/// Increase the counter corresponding to an identifier
41-
void increase_counter(const irep_idt &identifier)
41+
static void increase_counter(const current_namest::iterator &it)
4242
{
43-
PRECONDITION(current_names.find(identifier) != current_names.end());
44-
++current_names[identifier].second;
43+
++it->second.second;
4544
}
4645

4746
/// Add the \c ssa_exprt of current_names to vars

src/goto-symex/symex_dead.cpp

+3-3
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ void goto_symext::symex_dead(statet &state)
5252
state.propagation.erase(l1_identifier);
5353

5454
// L2 renaming
55-
if(state.level2.current_names.find(l1_identifier)!=
56-
state.level2.current_names.end())
57-
state.level2.increase_counter(l1_identifier);
55+
auto level2_it = state.level2.current_names.find(l1_identifier);
56+
if(level2_it != state.level2.current_names.end())
57+
symex_renaming_levelt::increase_counter(level2_it);
5858
}

src/goto-symex/symex_decl.cpp

+4-2
Original file line numberDiff line numberDiff line change
@@ -68,8 +68,10 @@ void goto_symext::symex_decl(statet &state, const symbol_exprt &expr)
6868
// L2 renaming
6969
// inlining may yield multiple declarations of the same identifier
7070
// within the same L1 context
71-
state.level2.current_names.emplace(l1_identifier, std::make_pair(ssa, 0));
72-
state.level2.increase_counter(l1_identifier);
71+
const auto level2_it =
72+
state.level2.current_names.emplace(l1_identifier, std::make_pair(ssa, 0))
73+
.first;
74+
symex_renaming_levelt::increase_counter(level2_it);
7375
const bool record_events=state.record_events;
7476
state.record_events=false;
7577
state.rename(ssa, ns);

src/goto-symex/symex_function_call.cpp

+5-4
Original file line numberDiff line numberDiff line change
@@ -408,7 +408,7 @@ void goto_symext::locality(
408408
const irep_idt l0_name=ssa.get_identifier();
409409

410410
// save old L1 name for popping the frame
411-
const auto c_it = state.level1.current_names.find(l0_name);
411+
auto c_it = state.level1.current_names.find(l0_name);
412412

413413
if(c_it != state.level1.current_names.end())
414414
{
@@ -417,8 +417,9 @@ void goto_symext::locality(
417417
}
418418
else
419419
{
420-
state.level1.current_names.emplace(
421-
l0_name, std::make_pair(ssa, frame_nr));
420+
c_it = state.level1.current_names
421+
.emplace(l0_name, std::make_pair(ssa, frame_nr))
422+
.first;
422423
}
423424

424425
// do L1 renaming -- these need not be unique, as
@@ -432,7 +433,7 @@ void goto_symext::locality(
432433

433434
while(state.l1_history.find(l1_name)!=state.l1_history.end())
434435
{
435-
state.level1.increase_counter(l0_name);
436+
symex_renaming_levelt::increase_counter(c_it);
436437
++offset;
437438
ssa.set_level_1(frame_nr+offset);
438439
l1_name=ssa.get_identifier();

0 commit comments

Comments
 (0)