Merge lp:~tapaal-ltl/verifypn/buchi-better-cleanup into lp:~tapaal-ltl/verifypn/ltl-model-checker

Proposed by Nikolaj Jensen Ulrik
Status: Merged
Merged at revision: 251
Proposed branch: lp:~tapaal-ltl/verifypn/buchi-better-cleanup
Merge into: lp:~tapaal-ltl/verifypn/ltl-model-checker
Diff against target: 81 lines (+33/-10)
1 file modified
include/LTL/BuchiSuccessorGenerator.h (+33/-10)
To merge this branch: bzr merge lp:~tapaal-ltl/verifypn/buchi-better-cleanup
Reviewer Review Type Date Requested Status
Simon Virenfeldt Approve
Review via email: mp+398065@code.launchpad.net

Description of the change

Use `spot::twa_graph_ptr::release_iter` instead of `delete` to clean-up used `spot::twa_succ_iterator`. According to the documentation, this lets spot reuse memory for iterators, thus saving heap allocation and deallocation steps. Uses custom deleter support in `std::unique_ptr` to accomplish this.

To post a comment you must log in.
Revision history for this message
Simon Virenfeldt (simwir) :
review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'include/LTL/BuchiSuccessorGenerator.h'
--- include/LTL/BuchiSuccessorGenerator.h 2021-02-01 11:17:38 +0000
+++ include/LTL/BuchiSuccessorGenerator.h 2021-02-15 13:10:57 +0000
@@ -29,44 +29,67 @@
29 class BuchiSuccessorGenerator {29 class BuchiSuccessorGenerator {
30 public:30 public:
31 explicit BuchiSuccessorGenerator(Structures::BuchiAutomaton automaton)31 explicit BuchiSuccessorGenerator(Structures::BuchiAutomaton automaton)
32 : aut(std::move(automaton)) {32 : aut(std::move(automaton))
33 {
34 deleter = SuccIterDeleter{&aut};
33 }35 }
3436
35 void prepare(size_t state) {37 void prepare(size_t state)
38 {
36 auto curstate = aut.buchi->state_from_number(state);39 auto curstate = aut.buchi->state_from_number(state);
37 succ = std::unique_ptr<spot::twa_succ_iterator>{aut.buchi->succ_iter(curstate)};40 succ = _succ_iter{aut.buchi->succ_iter(curstate), SuccIterDeleter{&aut}};
38 succ->first();41 succ->first();
39 }42 }
4043
41 bool next(size_t &state, bdd &cond) {44 bool next(size_t &state, bdd &cond)
45 {
42 if (!succ->done()) {46 if (!succ->done()) {
43 state = aut.buchi->state_number(succ->dst());47 auto dst = succ->dst();
48 state = aut.buchi->state_number(dst);
44 cond = succ->cond();49 cond = succ->cond();
45 succ->next();50 succ->next();
51 dst->destroy();
46 return true;52 return true;
47 }53 }
48 return false;54 return false;
49 }55 }
5056
51 [[nodiscard]] bool is_accepting(size_t state) const {57 [[nodiscard]] bool is_accepting(size_t state) const
58 {
52 return aut.buchi->state_is_accepting(state);59 return aut.buchi->state_is_accepting(state);
53 }60 }
5461
55 [[nodiscard]] size_t initial_state_number() const {62 [[nodiscard]] size_t initial_state_number() const
63 {
56 return aut.buchi->get_init_state_number();64 return aut.buchi->get_init_state_number();
57 }65 }
5866
59 [[nodiscard]] Condition_ptr getExpression(size_t i) const {67 [[nodiscard]] Condition_ptr getExpression(size_t i) const
68 {
60 return aut.ap_info.at(i).expression;69 return aut.ap_info.at(i).expression;
61 }70 }
6271
63 [[nodiscard]] bool is_weak() const {72 [[nodiscard]] bool is_weak() const
73 {
64 return (bool) aut.buchi->prop_weak();74 return (bool) aut.buchi->prop_weak();
65 }75 }
6676
67 private:77 private:
68 Structures::BuchiAutomaton aut;78 Structures::BuchiAutomaton aut;
69 std::unique_ptr<spot::twa_succ_iterator> succ;79
80 struct SuccIterDeleter {
81 Structures::BuchiAutomaton *aut;
82
83 void operator()(spot::twa_succ_iterator *iter) const
84 {
85 aut->buchi->release_iter(iter);
86 }
87 };
88
89 SuccIterDeleter deleter{};
90
91 using _succ_iter = std::unique_ptr<spot::twa_succ_iterator, SuccIterDeleter>;
92 _succ_iter succ = nullptr;
70 };93 };
71}94}
72#endif //VERIFYPN_BUCHISUCCESSORGENERATOR_H95#endif //VERIFYPN_BUCHISUCCESSORGENERATOR_H

Subscribers

People subscribed via source and target branches

to all changes: