3
0
Fork 0
mirror of https://github.com/Z3Prover/z3 synced 2025-04-08 10:25:18 +00:00

api_context: consolidate ast trail vectors

a context never changes between user rc/non-user rc, so we can reuse the trail for both options
and save memory & smallish speedup
This commit is contained in:
Nuno Lopes 2021-04-13 17:21:42 +01:00
parent f4127bd6f3
commit 853ce099ec
2 changed files with 7 additions and 12 deletions

View file

@ -81,7 +81,6 @@ namespace api {
m_fpa_util(m()),
m_sutil(m()),
m_recfun(m()),
m_last_result(m()),
m_ast_trail(m()),
m_pmanager(m_limit) {
@ -226,12 +225,12 @@ namespace api {
void context::save_ast_trail(ast * n) {
SASSERT(m().contains(n));
if (m_user_ref_count) {
// Corner case bug: n may be in m_last_result, and this is the only reference to n.
// Corner case bug: n may be in m_ast_trail, and this is the only reference to n.
// When, we execute reset() it is deleted
// To avoid this bug, I bump the reference counter before resetting m_last_result
// To avoid this bug, I bump the reference counter before resetting m_ast_trail
ast_ref node(n, m());
m_last_result.reset();
m_last_result.push_back(std::move(node));
m_ast_trail.reset();
m_ast_trail.push_back(std::move(node));
}
else {
m_ast_trail.push_back(n);
@ -239,15 +238,12 @@ namespace api {
}
void context::save_multiple_ast_trail(ast * n) {
if (m_user_ref_count)
m_last_result.push_back(n);
else
m_ast_trail.push_back(n);
m_ast_trail.push_back(n);
}
void context::reset_last_result() {
if (m_user_ref_count)
m_last_result.reset();
m_ast_trail.reset();
m_last_obj = nullptr;
}

View file

@ -91,8 +91,7 @@ namespace api {
smt_params m_fparams;
// -------------------------------
ast_ref_vector m_last_result; //!< used when m_user_ref_count == true
ast_ref_vector m_ast_trail; //!< used when m_user_ref_count == false
ast_ref_vector m_ast_trail;
ref<api::object> m_last_obj; //!< reference to the last API object returned by the APIs
u_map<api::object*> m_allocated_objects; // !< table containing current set of allocated API objects