Skip to content

Commit d951013

Browse files
committed
replace_history_parametert: use an unordered map to symbol_exprt
There are no ordering requirements here, so we can benefit from O(1) amortised cost. Also, the value type is always a `symbol_exprt`, not just a generic `exprt`.
1 parent ef24d8e commit d951013

File tree

4 files changed

+11
-13
lines changed

4 files changed

+11
-13
lines changed

src/goto-instrument/contracts/dynamic-frames/dfcc_instrument_loop.cpp

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,7 @@ void dfcc_instrument_loopt::operator()(
167167
goto_programt::targett loop_latch =
168168
loop.find_latch(goto_function.body).value();
169169

170-
const auto &history_var_map = add_prehead_instructions(
170+
const auto history_var_map = add_prehead_instructions(
171171
loop_id,
172172
goto_function,
173173
symbol_table,
@@ -234,7 +234,8 @@ void dfcc_instrument_loopt::operator()(
234234
goto_function.body.update();
235235
}
236236

237-
std::map<exprt, exprt> dfcc_instrument_loopt::add_prehead_instructions(
237+
std::unordered_map<exprt, symbol_exprt, irep_hash>
238+
dfcc_instrument_loopt::add_prehead_instructions(
238239
const std::size_t loop_id,
239240
goto_functionst::goto_functiont &goto_function,
240241
symbol_tablet &symbol_table,
@@ -605,7 +606,7 @@ void dfcc_instrument_loopt::add_exit_instructions(
605606
goto_programt::targett loop_head,
606607
const symbol_exprt &loop_write_set,
607608
const symbol_exprt &addr_of_loop_write_set,
608-
const std::map<exprt, exprt> &history_var_map,
609+
const std::unordered_map<exprt, symbol_exprt, irep_hash> &history_var_map,
609610
const symbol_exprt &entered_loop,
610611
const symbol_exprt &initial_invariant,
611612
const symbol_exprt &in_base_case,
@@ -681,10 +682,7 @@ void dfcc_instrument_loopt::add_exit_instructions(
681682

682683
// Mark history variables as going out of scope.
683684
for(const auto &v : history_var_map)
684-
{
685-
loop_exit_program.add(
686-
goto_programt::make_dead(to_symbol_expr(v.second), exit_location));
687-
}
685+
loop_exit_program.add(goto_programt::make_dead(v.second, exit_location));
688686

689687
// Mark decreases clause snapshots as gong out of scope.
690688
for(size_t i = 0; i < old_decreases_vars.size(); i++)

src/goto-instrument/contracts/dynamic-frames/dfcc_instrument_loop.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -197,7 +197,7 @@ class dfcc_instrument_loopt
197197
/// \param[in] in_base_case temporary variable `in_base_case`.
198198
/// \param[in] symbol_mode Language mode of the function.
199199
/// \return `history_var_map` that maps variables to loop_entry variables.
200-
std::map<exprt, exprt> add_prehead_instructions(
200+
std::unordered_map<exprt, symbol_exprt, irep_hash> add_prehead_instructions(
201201
const std::size_t loop_id,
202202
goto_functionst::goto_functiont &goto_function,
203203
symbol_tablet &symbol_table,
@@ -348,7 +348,7 @@ class dfcc_instrument_loopt
348348
goto_programt::targett loop_head,
349349
const symbol_exprt &loop_write_set,
350350
const symbol_exprt &addr_of_loop_write_set,
351-
const std::map<exprt, exprt> &history_var_map,
351+
const std::unordered_map<exprt, symbol_exprt, irep_hash> &history_var_map,
352352
const symbol_exprt &entered_loop,
353353
const symbol_exprt &initial_invariant,
354354
const symbol_exprt &in_base_case,

src/goto-instrument/contracts/utils.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -453,7 +453,7 @@ void add_quantified_variable(
453453
static void replace_history_parameter_rec(
454454
symbol_table_baset &symbol_table,
455455
exprt &expr,
456-
std::map<exprt, exprt> &parameter2history,
456+
std::unordered_map<exprt, symbol_exprt, irep_hash> &parameter2history,
457457
const source_locationt &location,
458458
const irep_idt &mode,
459459
goto_programt &history,
@@ -492,7 +492,7 @@ static void replace_history_parameter_rec(
492492

493493
// 2. Associate the above temporary variable to it's corresponding
494494
// expression
495-
parameter2history[parameter] = tmp_symbol;
495+
it = parameter2history.emplace(parameter, tmp_symbol).first;
496496

497497
// 3. Add the required instructions to the instructions list
498498
// 3.1. Declare the newly created temporary variable
@@ -515,7 +515,7 @@ static void replace_history_parameter_rec(
515515
history.destructive_append(skip_program);
516516
}
517517

518-
expr = parameter2history[parameter];
518+
expr = it->second;
519519
}
520520
else
521521
{

src/goto-instrument/contracts/utils.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -245,7 +245,7 @@ void add_quantified_variable(
245245
struct replace_history_parametert
246246
{
247247
exprt expression_after_replacement;
248-
std::map<exprt, exprt> parameter_to_history;
248+
std::unordered_map<exprt, symbol_exprt, irep_hash> parameter_to_history;
249249
goto_programt history_construction;
250250
};
251251

0 commit comments

Comments
 (0)