Skip to content

Commit 4743cb9

Browse files
committed
goto trace storage: use a list instead of a vector
goto traces consume a lot of memory, and re-allocating them for each incremental addition of a goto trace does not seem to be a good approach. This is at the expense of more costly indexed access, which now requires iterator increments.
1 parent d613b01 commit 4743cb9

File tree

2 files changed

+7
-4
lines changed

2 files changed

+7
-4
lines changed

src/goto-checker/goto_trace_storage.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ const goto_tracet &goto_trace_storaget::insert_all(goto_tracet &&trace)
4343
return traces.back();
4444
}
4545

46-
const std::vector<goto_tracet> &goto_trace_storaget::all() const
46+
const std::list<goto_tracet> &goto_trace_storaget::all() const
4747
{
4848
return traces;
4949
}
@@ -53,8 +53,9 @@ operator[](const irep_idt &property_id) const
5353
{
5454
const auto trace_found = property_id_to_trace_index.find(property_id);
5555
PRECONDITION(trace_found != property_id_to_trace_index.end());
56+
CHECK_RETURN(trace_found->second < traces.size());
5657

57-
return traces.at(trace_found->second);
58+
return *(std::next(traces.begin(), trace_found->second));
5859
}
5960

6061
const namespacet &goto_trace_storaget::get_namespace() const

src/goto-checker/goto_trace_storage.h

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ Author: Daniel Kroening, Peter Schrammel
1414

1515
#include <goto-programs/goto_trace.h>
1616

17+
#include <list>
18+
1719
class goto_trace_storaget
1820
{
1921
public:
@@ -28,7 +30,7 @@ class goto_trace_storaget
2830
/// are mapped to the given trace.
2931
const goto_tracet &insert_all(goto_tracet &&);
3032

31-
const std::vector<goto_tracet> &all() const;
33+
const std::list<goto_tracet> &all() const;
3234
const goto_tracet &operator[](const irep_idt &property_id) const;
3335

3436
const namespacet &get_namespace() const;
@@ -38,7 +40,7 @@ class goto_trace_storaget
3840
const namespacet &ns;
3941

4042
/// stores the traces
41-
std::vector<goto_tracet> traces;
43+
std::list<goto_tracet> traces;
4244

4345
// maps property ID to index in traces
4446
std::unordered_map<irep_idt, std::size_t> property_id_to_trace_index;

0 commit comments

Comments
 (0)