Skip to content

Commit a70b84a

Browse files
committed
Tweak allocator usage
1 parent 495ad35 commit a70b84a

File tree

2 files changed

+11
-30
lines changed

2 files changed

+11
-30
lines changed

include/split_rect.h

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
#include <type_traits>
1111
#include <set>
1212
#include <boost/icl/interval_map.hpp>
13+
#include <boost/pool/pool_alloc.hpp>
1314

1415
#include "rect.h"
1516

@@ -73,10 +74,12 @@ operator!=(const Event<T> &lhs, const Event<T> &rhs) noexcept {
7374
return !(lhs == rhs);
7475
}
7576

77+
template<typename T>
78+
using interval_allocator = boost::fast_pool_allocator<T>;
79+
7680
template<
7781
typename Iterator,
78-
typename OutIterator,
79-
template<typename T> typename Allocator = std::allocator
82+
typename OutIterator
8083
>
8184
OutIterator split_rectangles(Iterator begin, Iterator end, OutIterator result) {
8285
using rect_t = std::remove_cv_t<std::remove_reference_t<decltype(*begin)>>;
@@ -85,19 +88,16 @@ OutIterator split_rectangles(Iterator begin, Iterator end, OutIterator result) {
8588

8689
// queue of events
8790
std::multiset<
88-
event_t
91+
event_t,
92+
std::less<event_t>,
93+
boost::fast_pool_allocator<event_t>
8994
> events;
9095

9196
// control the events of rects that are no longer valid
9297
// this is necessary because a rect becomes invalid (because
9398
// we splitted it) in an enter event, we should mark the leave
9499
// event of this specific rectangle as invalid as well
95-
std::unordered_set<
96-
std::uint64_t,
97-
std::hash<std::uint64_t>,
98-
std::equal_to<std::uint64_t>,
99-
Allocator<std::uint64_t>
100-
> removed;
100+
std::unordered_set<std::uint64_t> removed;
101101

102102
std::uint64_t cur_id = 0;
103103
// create an enter and leave events for the rectangle
@@ -124,7 +124,7 @@ OutIterator split_rectangles(Iterator begin, Iterator end, OutIterator result) {
124124
ICL_SECTION_INSTANCE(boost::icl::inter_section, size_type),
125125
ICL_INTERVAL_INSTANCE(ICL_INTERVAL_DEFAULT, size_type,
126126
ICL_COMPARE_INSTANCE(ICL_COMPARE_DEFAULT, size_type)),
127-
Allocator
127+
interval_allocator
128128
> intervals;
129129

130130
// the rects difference operations produces no more than 8 new rectangles

tests/benchmark.cc

Lines changed: 1 addition & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
#include <random>
22
#include <vector>
33
#include <algorithm>
4-
#include <boost/pool/pool_alloc.hpp>
54

65
#define CATCH_CONFIG_MAIN
76
#define CATCH_CONFIG_ENABLE_BENCHMARKING
@@ -27,11 +26,8 @@ std::vector<Rect<T>> gen_data() {
2726
return recs;
2827
}
2928

30-
template<typename T>
31-
using pool_allocator = boost::fast_pool_allocator<T>;
32-
3329
TEST_CASE("split_rectangles") {
34-
BENCHMARK_ADVANCED("default allocator")(Catch::Benchmark::Chronometer meter) {
30+
BENCHMARK_ADVANCED("default")(Catch::Benchmark::Chronometer meter) {
3531
auto recs = gen_data<int>();
3632
std::vector<Rect<int>> result;
3733
auto inserter = std::back_inserter(recs);
@@ -41,19 +37,4 @@ TEST_CASE("split_rectangles") {
4137
});
4238
};
4339

44-
#if 0
45-
BENCHMARK_ADVANCED("boost pool allocator")(Catch::Benchmark::Chronometer meter) {
46-
auto recs = gen_data<int>();
47-
std::vector<Rect<int>> result;
48-
auto inserter = std::back_inserter(recs);
49-
50-
meter.measure([&] {
51-
return split_rectangles<
52-
decltype(recs.cbegin()),
53-
decltype(inserter),
54-
pool_allocator
55-
>(recs.cbegin(), recs.cend(), std::back_inserter(result));
56-
});
57-
};
58-
#endif
5940
}

0 commit comments

Comments
 (0)