chrono_batch_render/
Coverage:
low: ≥ 0%
medium: ≥ 75.0%
high: ≥ 90.0%
Lines:
17 / 17
100.0%
Branches:
9 / 9
100.0%
Functions:
4 / 4
100.0%

stage/structure/tokens.cpp
Line Branch Exec Source
1 // SPDX-License-Identifier: BSD-3-Clause
2 #include "chrono_batch_render/stage/structure/tokens.h"
3
4 #include "chrono_batch_render/util/error.h"
5
6 namespace chrono::batch_render {
7
8
1/1
✓ Branch 2 taken 511 times.
511 Tokens::Tokens() {
9
1/1
✓ Branch 1 taken 511 times.
511 Intern("");
10 511 }
11
12 51284 Token Tokens::Intern(std::string_view text) {
13
2/2
✓ Branch 1 taken 12708 times.
✓ Branch 2 taken 38576 times.
51284 if (const auto found = m_ids.find(text); found != m_ids.end()) {
14 12708 return {found->second};
15 }
16 38576 const uint32_t id = uint32_t(m_texts.size());
17 38576 const std::string& stored = m_texts.emplace_back(text);
18 38576 m_ids.emplace(stored, id);
19 38576 return {id};
20 }
21
22 152678 Token Tokens::Find(std::string_view text) const {
23 152678 const auto found = m_ids.find(text);
24
2/2
✓ Branch 0 taken 49810 times.
✓ Branch 1 taken 102868 times.
255546 return found == m_ids.end() ? Token{} : Token{found->second};
25 }
26
27 20689 std::string_view Tokens::Text(Token token) const {
28
2/2
✓ Branch 0 taken 1 time.
✓ Branch 1 taken 20688 times.
20689 if (token.id >= m_texts.size()) {
29
1/1
✓ Branch 2 taken 1 time.
1 throw Error("No token {}", token.id);
30 }
31 20688 return m_texts[token.id];
32 }
33
34 }
35