Skip to content

Commit

Permalink
Reserve vector capacity
Browse files Browse the repository at this point in the history
  • Loading branch information
unageek committed Sep 10, 2024
1 parent 398d1b9 commit a74d0fe
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 5 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ Here are the timings (in seconds) for computing the Boolean intersection between
|-------------------|-----------------------:|--------------------------:|---------------:|--------------:|-----------------------:|---------------:|
| **Open** | 4.6 | FAILED | 2.4 | 1.3 | FAILED | FAILED |
| **Open & closed** | FAILED | 70.5 | 1.6 | 0.9 | FAILED | FAILED |
| **Closed** | 57.4 | FAILED | 5.4 | 2.7 | 8.9 | 1.7 |
| **Closed** | 57.4 | FAILED | 5.3 | 2.7 | 8.9 | 1.7 |
| **Non-manifold** | FAILED | FAILED | 0.5 | 0.3 | FAILED | FAILED |

¹ Ran with `KIGUMI_NUM_THREADS=1`. ² Configured with `-DMANIFOLD_PAR=TBB`.
Expand Down
10 changes: 6 additions & 4 deletions include/kigumi/Triangle_mesh.h
Original file line number Diff line number Diff line change
Expand Up @@ -104,20 +104,22 @@ class Triangle_mesh {

void finalize() {
std::vector<std::pair<Vertex_index, Face_index>> map;
std::size_t face_index{};
map.reserve(3 * faces_.size());
Face_index fi{0};
for (const auto& face : faces_) {
Face_index fi{face_index};
map.emplace_back(face[0], fi);
map.emplace_back(face[1], fi);
map.emplace_back(face[2], fi);
++face_index;
++fi;
}

parallel_sort(map.begin(), map.end());

face_indices_.reserve(3 * faces_.size());
indices_.reserve(points_.size() + 1);
std::size_t index{};
std::ptrdiff_t prev_v{-1};
for (const auto& [vi, fi] : map) {
for (auto [vi, fi] : map) {
face_indices_.push_back(fi);

auto v = static_cast<std::ptrdiff_t>(vi.idx());
Expand Down

0 comments on commit a74d0fe

Please sign in to comment.