Skip to content

Commit 853ce97

Browse files
marek-trtiktautschnig
authored andcommitted
Using cache to speed up generation of GrapML file.
Expression-to-string conversion is costly.
1 parent 39bc799 commit 853ce97

File tree

1 file changed

+32
-0
lines changed

1 file changed

+32
-0
lines changed

src/goto-programs/graphml_witness.cpp

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,10 +61,41 @@ void graphml_witnesst::remove_l0_l1(exprt &expr)
6161
remove_l0_l1(*it);
6262
}
6363

64+
template <typename T>
65+
inline void hash_combine(std::size_t &seed, const T &v)
66+
{
67+
std::hash<T> hasher;
68+
seed ^= hasher(v) + 0x9e3779b9 + (seed << 6) + (seed >> 2);
69+
}
70+
71+
namespace std
72+
{
73+
template <typename S, typename T>
74+
struct hash<pair<S, T>>
75+
{
76+
inline size_t operator()(const pair<S, T> &v) const
77+
{
78+
size_t seed = 0;
79+
::hash_combine(seed, v.first);
80+
::hash_combine(seed, v.second);
81+
return seed;
82+
}
83+
};
84+
} // namespace std
85+
6486
std::string graphml_witnesst::convert_assign_rec(
6587
const irep_idt &identifier,
6688
const code_assignt &assign)
6789
{
90+
static std::
91+
unordered_map<std::pair<unsigned int, const irept::dt *>, std::string>
92+
cache;
93+
{
94+
const auto cit = cache.find({identifier.get_no(), &assign.read()});
95+
if(cit != cache.end())
96+
return cit->second;
97+
}
98+
6899
std::string result;
69100

70101
if(assign.rhs().id() == ID_array_list)
@@ -195,6 +226,7 @@ std::string graphml_witnesst::convert_assign_rec(
195226
result = lhs + " = " + expr_to_string(ns, identifier, clean_rhs) + ";";
196227
}
197228

229+
cache.insert({{identifier.get_no(), &assign.read()}, result});
198230
return result;
199231
}
200232

0 commit comments

Comments
 (0)