@@ -11,27 +11,11 @@ namespace floormat {
11
11
12
12
Pointer<path_search_result::node> path_search_result::_pool; // NOLINT
13
13
14
- path_search_result::path_search_result ()
15
- {
16
- constexpr auto min_length = TILE_MAX_DIM*2 ;
17
- if (_pool)
18
- {
19
- auto ptr = move (_pool);
20
- fm_debug_assert (ptr->vec .empty ());
21
- auto next = move (ptr->_next );
22
- _node = move (ptr);
23
- _pool = move (next);
24
- }
25
- else
26
- {
27
- _node = Pointer<node>{InPlaceInit};
28
- _node->vec .reserve (min_length);
29
- }
30
- }
14
+ path_search_result::path_search_result () = default ;
31
15
32
16
path_search_result::~path_search_result () noexcept
33
17
{
34
- if (_node && _node->vec .capacity () > 0 ) [[likely]]
18
+ if (_node && _node->vec .capacity () > 0 )
35
19
{
36
20
_node->vec .clear ();
37
21
_node->_next = move (_pool);
@@ -52,7 +36,7 @@ path_search_result& path_search_result::operator=(const path_search_result& x) n
52
36
{
53
37
fm_debug_assert (_node);
54
38
fm_debug_assert (!_node->_next );
55
- if (&x != this )
39
+ if (&x != this ) [[likely]]
56
40
_node->vec = x._node ->vec ;
57
41
_cost = x._cost ;
58
42
return *this ;
@@ -79,20 +63,65 @@ path_search_result& path_search_result::operator=(path_search_result&& other) no
79
63
return *this ;
80
64
}
81
65
82
- size_t path_search_result::size () const { return _node->vec .size (); }
83
- bool path_search_result::empty () const { return _node->vec .empty (); }
66
+ void path_search_result::allocate_node ()
67
+ {
68
+ constexpr auto min_length = TILE_MAX_DIM*2 ;
69
+
70
+ if (_node)
71
+ return ;
72
+
73
+ if (_pool)
74
+ {
75
+ auto ptr = move (_pool);
76
+ fm_debug_assert (ptr->vec .empty ());
77
+ auto next = move (ptr->_next );
78
+ _node = move (ptr);
79
+ _pool = move (next);
80
+ }
81
+ else
82
+ {
83
+ _node = Pointer<node>{InPlaceInit};
84
+ _node->vec .reserve (min_length);
85
+ }
86
+ }
87
+
88
+ ArrayView<const point> path_search_result::path () const
89
+ {
90
+ if (!_node)
91
+ return {};
92
+ return { _node->vec .data (), _node->vec .size () };
93
+ }
94
+
95
+ vector_wrapper<point, vector_wrapper_repr::ref> path_search_result::raw_path ()
96
+ {
97
+ if (!_node)
98
+ allocate_node ();
99
+ return {_node->vec };
100
+ }
101
+
102
+ size_t path_search_result::size () const
103
+ {
104
+ return _node ? _node->vec .size () : 0 ;
105
+ }
106
+
107
+ bool path_search_result::empty () const
108
+ {
109
+ return !_node || _node->vec .empty ();
110
+ }
111
+
112
+ path_search_result::operator bool () const
113
+ {
114
+ return _node && !_node->vec .empty ();
115
+ }
116
+
84
117
path_search_result::node::node () noexcept = default ;
85
118
float path_search_result::time () const { return _time; }
86
-
87
119
uint32_t path_search_result::cost () const { return _cost; }
88
120
void path_search_result::set_cost (uint32_t value) { _cost = value; }
89
121
void path_search_result::set_time (float time) { _time = time ; }
90
122
bool path_search_result::is_found () const { return _found; }
91
123
void path_search_result::set_found (bool value) { _found = value; }
92
124
uint32_t path_search_result::distance () const { return _distance; }
93
125
void path_search_result::set_distance (uint32_t dist) { _distance = dist; }
94
- path_search_result::operator bool () const { return !_node->vec .empty (); }
95
- ArrayView<const point> path_search_result::path () const { fm_assert (_node); return {_node->vec .data (), _node->vec .size ()}; }
96
- vector_wrapper<point, vector_wrapper_repr::ref> path_search_result::raw_path () { fm_assert (_node); return {_node->vec }; }
97
126
98
127
} // namespace floormat
0 commit comments