GCC Code Coverage Report


ernie/
Coverage:
low: ≥ 0%
medium: ≥ 75.0%
high: ≥ 90.0%
Lines:
37 / 43
86.0%
Branches:
24 / 45
53.3%
Functions:
3 / 3
100.0%

render/prim_rows.cpp
Line Branch Exec Source
1 // SPDX-License-Identifier: BSD-3-Clause
2 /// @file prim_rows.cpp
3 /// @brief Replaying bucket row logs.
4 #include "ernie/render/prim_rows.h"
5
6 #include "ernie/util/profiler.h"
7
8 #include <algorithm>
9
10 namespace ernie {
11 namespace {
12
13 /// A row added since the last replay, whose prim is read from the bucket afterwards.
14 3030 bool IsPlaceholder(PrimId prim) {
15 3030 return prim.slot == PrimId().slot;
16 }
17
18 } // namespace
19
20 77 PrimRows::Changes PrimRows::Follow(const PrimStore& store, const ChangeSet& changes) {
21 77 ERNIE_ZONE("Follow the buckets' rows");
22
1/2
✓ Branch 1 taken 77 times.
✗ Branch 2 not taken.
77 rows_.resize(store.BucketCount());
23 77 Changes result;
24 77 std::vector<BucketId> touched;
25
2/2
✓ Branch 0 taken 1642 times.
✓ Branch 1 taken 77 times.
1719 for (const ChangeSet::Rows& entry : changes.rows) {
26
1/2
✓ Branch 1 taken 1642 times.
✗ Branch 2 not taken.
1642 std::vector<PrimId>& rows = rows_[entry.bucket];
27 1642 const StructuralChange& change = entry.change;
28
1/2
✓ Branch 1 taken 1642 times.
✗ Branch 2 not taken.
1642 touched.push_back(entry.bucket);
29
3/5
✓ Branch 0 taken 1620 times.
✓ Branch 1 taken 13 times.
✓ Branch 2 taken 9 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
1642 switch (change.kind) {
30 1620 case StructuralChange::Kind::Added:
31
1/2
✓ Branch 1 taken 1620 times.
✗ Branch 2 not taken.
1620 rows.resize(change.row + change.count, PrimId());
32 1620 break;
33 13 case StructuralChange::Kind::Removed:
34
1/2
✓ Branch 0 taken 13 times.
✗ Branch 1 not taken.
13 if (!IsPlaceholder(rows[change.row])) {
35
1/2
✓ Branch 1 taken 13 times.
✗ Branch 2 not taken.
13 result.removed.push_back(rows[change.row]);
36 }
37 // Unless it was the last, a Moved change brings the last row here next.
38
2/2
✓ Branch 0 taken 4 times.
✓ Branch 1 taken 9 times.
13 if (change.row + 1 == rows.size()) {
39 4 rows.pop_back();
40 }
41 break;
42 9 case StructuralChange::Kind::Moved:
43 9 rows[change.row] = rows[change.from];
44 9 rows.pop_back();
45
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 if (!IsPlaceholder(rows[change.row])) {
46
1/2
✓ Branch 1 taken 9 times.
✗ Branch 2 not taken.
9 result.moved.push_back(rows[change.row]);
47 }
48 break;
49 ✗ case StructuralChange::Kind::Reset:
50
0/2
✗ Branch 0 not taken.
✗ Branch 1 not taken.
✗ for (const PrimId prim : rows) {
51
0/2
✗ Branch 0 not taken.
✗ Branch 1 not taken.
✗ if (!IsPlaceholder(prim)) {
52
0/2
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✗ result.removed.push_back(prim);
53 }
54 }
55
0/2
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✗ rows.assign(change.count, PrimId());
56 ✗ break;
57 }
58 }
59 77 std::ranges::sort(touched);
60 77 touched.erase(std::ranges::unique(touched).begin(), touched.end());
61
2/2
✓ Branch 0 taken 100 times.
✓ Branch 1 taken 77 times.
177 for (const BucketId bucket : touched) {
62 100 std::vector<PrimId>& rows = rows_[bucket];
63 100 const std::vector<PrimId>& now = store.GetBucket(bucket).prims;
64
2/2
✓ Branch 0 taken 3008 times.
✓ Branch 1 taken 100 times.
3108 for (std::size_t row = 0; row < rows.size(); ++row) {
65
2/2
✓ Branch 0 taken 1620 times.
✓ Branch 1 taken 1388 times.
3008 if (IsPlaceholder(rows[row])) {
66
1/2
✓ Branch 1 taken 1620 times.
✗ Branch 2 not taken.
1620 rows[row] = now[row];
67
1/2
✓ Branch 1 taken 1620 times.
✗ Branch 2 not taken.
1620 result.added.push_back(now[row]);
68 }
69 }
70 }
71 // Parents before children: ancestors' paths are interned first.
72
1/2
✓ Branch 1 taken 77 times.
✗ Branch 2 not taken.
30951 std::ranges::sort(result.added, {}, [&](PrimId prim) { return store.PrimPath(prim); });
73 77 return result;
74 77 }
75
76 } // namespace ernie
77