| Line | Branch | Decision | Exec | Source |
|---|---|---|---|---|
| 1 | #pragma once | |||
| 2 | ||||
| 3 | template <typename T, int TSlots> | |||
| 4 | struct static_vector { | |||
| 5 | ||||
| 6 | 680 | void clear() { | ||
| 7 | 680 | m_size = 0; | ||
| 8 | 680 | } | ||
| 9 | ||||
| 10 | template <typename TSearch> | |||
| 11 | 3554 | T* find(const TSearch& search) const { | ||
| 12 |
2/2✓ Branch 0 taken 7891 times.
✓ Branch 1 taken 296 times.
|
2/2✓ Decision 'true' taken 7891 times.
✓ Decision 'false' taken 296 times.
|
8187 | for (size_t i = 0; i < m_size; i++) { |
| 13 |
2/2✓ Branch 2 taken 3258 times.
✓ Branch 3 taken 4633 times.
|
2/2✓ Decision 'true' taken 3258 times.
✓ Decision 'false' taken 4633 times.
|
7891 | if (m_storage[i] == search) { |
| 14 | 3258 | return const_cast<T*>(&m_storage[i]); | ||
| 15 | } | |||
| 16 | } | |||
| 17 | ||||
| 18 | 296 | return nullptr; | ||
| 19 | } | |||
| 20 | ||||
| 21 | 148 | T* add(const T& value) { | ||
| 22 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 148 times.
|
1/2✗ Decision 'true' not taken.
✓ Decision 'false' taken 148 times.
|
148 | if (m_size >= TSlots) { |
| 23 | // vector full, discard | |||
| 24 | ✗ | return nullptr; | ||
| 25 | } | |||
| 26 | ||||
| 27 | 148 | T& location = m_storage[m_size]; | ||
| 28 | ||||
| 29 | 148 | location = value; | ||
| 30 | 148 | m_size++; | ||
| 31 | ||||
| 32 | 148 | return &location; | ||
| 33 | } | |||
| 34 | ||||
| 35 | 254429 | T& get(size_t i) { | ||
| 36 | 254429 | return m_storage[i]; | ||
| 37 | } | |||
| 38 | ||||
| 39 | 785538 | size_t getCount() const { | ||
| 40 | 785538 | return m_size; | ||
| 41 | } | |||
| 42 | ||||
| 43 | private: | |||
| 44 | T m_storage[TSlots]; | |||
| 45 | // wow: order of field declaration matters here, gcc glitch? | |||
| 46 | size_t m_size = 0; | |||
| 47 | }; | |||
| 48 |