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
1=== modified file 'include/LTL/BuchiSuccessorGenerator.h'
2--- include/LTL/BuchiSuccessorGenerator.h 2021-02-01 11:17:38 +0000
3+++ include/LTL/BuchiSuccessorGenerator.h 2021-02-15 13:10:57 +0000
4@@ -29,44 +29,67 @@
5 class BuchiSuccessorGenerator {
6 public:
7 explicit BuchiSuccessorGenerator(Structures::BuchiAutomaton automaton)
8- : aut(std::move(automaton)) {
9+ : aut(std::move(automaton))
10+ {
11+ deleter = SuccIterDeleter{&aut};
12 }
13
14- void prepare(size_t state) {
15+ void prepare(size_t state)
16+ {
17 auto curstate = aut.buchi->state_from_number(state);
18- succ = std::unique_ptr<spot::twa_succ_iterator>{aut.buchi->succ_iter(curstate)};
19+ succ = _succ_iter{aut.buchi->succ_iter(curstate), SuccIterDeleter{&aut}};
20 succ->first();
21 }
22
23- bool next(size_t &state, bdd &cond) {
24+ bool next(size_t &state, bdd &cond)
25+ {
26 if (!succ->done()) {
27- state = aut.buchi->state_number(succ->dst());
28+ auto dst = succ->dst();
29+ state = aut.buchi->state_number(dst);
30 cond = succ->cond();
31 succ->next();
32+ dst->destroy();
33 return true;
34 }
35 return false;
36 }
37
38- [[nodiscard]] bool is_accepting(size_t state) const {
39+ [[nodiscard]] bool is_accepting(size_t state) const
40+ {
41 return aut.buchi->state_is_accepting(state);
42 }
43
44- [[nodiscard]] size_t initial_state_number() const {
45+ [[nodiscard]] size_t initial_state_number() const
46+ {
47 return aut.buchi->get_init_state_number();
48 }
49
50- [[nodiscard]] Condition_ptr getExpression(size_t i) const {
51+ [[nodiscard]] Condition_ptr getExpression(size_t i) const
52+ {
53 return aut.ap_info.at(i).expression;
54 }
55
56- [[nodiscard]] bool is_weak() const {
57+ [[nodiscard]] bool is_weak() const
58+ {
59 return (bool) aut.buchi->prop_weak();
60 }
61
62 private:
63 Structures::BuchiAutomaton aut;
64- std::unique_ptr<spot::twa_succ_iterator> succ;
65+
66+ struct SuccIterDeleter {
67+ Structures::BuchiAutomaton *aut;
68+
69+ void operator()(spot::twa_succ_iterator *iter) const
70+ {
71+ aut->buchi->release_iter(iter);
72+ }
73+ };
74+
75+ SuccIterDeleter deleter{};
76+
77+ using _succ_iter = std::unique_ptr<spot::twa_succ_iterator, SuccIterDeleter>;
78+ _succ_iter succ = nullptr;
79 };
80 }
81 #endif //VERIFYPN_BUCHISUCCESSORGENERATOR_H

Subscribers

People subscribed via source and target branches

to all changes: