Skip to content

Commit 51fcb10

Browse files
shave some overhead from fingerprint hash function #7281
1 parent 7c30cbf commit 51fcb10

File tree

2 files changed

+27
-9
lines changed

2 files changed

+27
-9
lines changed

src/smt/fingerprints.cpp

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,26 @@ namespace smt {
6363

6464

6565
fingerprint * fingerprint_set::insert(void * data, unsigned data_hash, unsigned num_args, enode * const * args, expr* def) {
66+
67+
struct arg_data {
68+
unsigned data_hash;
69+
enode* const* args;
70+
};
71+
struct khash {
72+
unsigned operator()(arg_data const& d) const {
73+
return d.data_hash;
74+
}
75+
};
76+
struct arghash {
77+
unsigned operator()(arg_data const& d, unsigned i) const {
78+
return d.args[i]->hash();
79+
}
80+
};
81+
arg_data arg_data({ data_hash, args });
82+
khash kh;
83+
arghash ah;
84+
data_hash = get_composite_hash(arg_data, num_args, kh, ah);
85+
6686
fingerprint * d = mk_dummy(data, data_hash, num_args, args);
6787
if (m_set.contains(d))
6888
return nullptr;
@@ -107,8 +127,12 @@ namespace smt {
107127
unsigned new_lvl = lvl - num_scopes;
108128
unsigned old_size = m_scopes[new_lvl];
109129
unsigned size = m_fingerprints.size();
110-
for (unsigned i = old_size; i < size; i++)
111-
m_set.erase(m_fingerprints[i]);
130+
if (old_size == 0 && size > 0)
131+
m_set.reset();
132+
else {
133+
for (unsigned i = old_size; i < size; i++)
134+
m_set.erase(m_fingerprints[i]);
135+
}
112136
m_fingerprints.shrink(old_size);
113137
m_defs.shrink(old_size);
114138
m_scopes.shrink(new_lvl);

src/smt/fingerprints.h

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -48,15 +48,9 @@ namespace smt {
4848

4949
class fingerprint_set {
5050

51-
struct fingerprint_khasher {
52-
unsigned operator()(fingerprint const * f) const { return f->get_data_hash(); }
53-
};
54-
struct fingerprint_chasher {
55-
unsigned operator()(fingerprint const * f, unsigned idx) const { return f->get_arg(idx)->hash(); }
56-
};
5751
struct fingerprint_hash_proc {
5852
unsigned operator()(fingerprint const * f) const {
59-
return get_composite_hash<fingerprint *, fingerprint_khasher, fingerprint_chasher>(const_cast<fingerprint*>(f), f->get_num_args());
53+
return f->get_data_hash();
6054
}
6155
};
6256
struct fingerprint_eq_proc { bool operator()(fingerprint const * f1, fingerprint const * f2) const; };

0 commit comments

Comments
 (0)