Skip to content

Commit 4f33ca0

Browse files
committed
small cleanup
1 parent c68c883 commit 4f33ca0

1 file changed

Lines changed: 7 additions & 11 deletions

File tree

include/mapbox/earcut.hpp

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -147,9 +147,8 @@ class Earcut {
147147
template <typename T, typename Alloc = std::allocator<T>>
148148
class ObjectPool {
149149
public:
150-
ObjectPool() { allocateNewBlock(256); }
151-
ObjectPool(std::size_t blockSize_) : baseBlockSize(blockSize_) {
152-
allocateNewBlock(std::max<std::size_t>(blockSize_, 256));
150+
ObjectPool(std::size_t blockSize_) : baseBlockSize(std::max<std::size_t>(blockSize_, 256)) {
151+
allocateNewBlock();
153152
}
154153
~ObjectPool() { clear(); }
155154
template <typename... Args>
@@ -162,7 +161,7 @@ class Earcut {
162161
currentIndex = 0;
163162
} else {
164163
// Allocate a new one
165-
allocateNewBlock(baseBlockSize);
164+
allocateNewBlock();
166165
}
167166
}
168167

@@ -172,7 +171,6 @@ class Earcut {
172171
currentIndex++;
173172
return object;
174173
}
175-
void reset() { clear(); }
176174
void clear() {
177175
// Destroy all objects, but keep blocks allocated for reuse
178176
std::size_t objectsDestroyed = 0;
@@ -204,17 +202,15 @@ class Earcut {
204202
};
205203

206204
std::vector<std::unique_ptr<T[], AllocDeleter>> memoryBlocks;
207-
std::vector<std::size_t> blockCapacities;
208205
std::size_t currentBlockIndex = 0;
209206
std::size_t currentIndex = 0;
210207
std::size_t totalObjects = 0;
211-
std::size_t baseBlockSize = 256;
208+
const std::size_t baseBlockSize;
212209

213-
void allocateNewBlock(std::size_t capacity) {
214-
T* rawMemory = alloc_traits::allocate(alloc, capacity);
215-
auto newBlock = std::unique_ptr<T[], AllocDeleter>(rawMemory, AllocDeleter{alloc, capacity});
210+
void allocateNewBlock() {
211+
T* rawMemory = alloc_traits::allocate(alloc, baseBlockSize);
212+
auto newBlock = std::unique_ptr<T[], AllocDeleter>(rawMemory, AllocDeleter{alloc, baseBlockSize});
216213
memoryBlocks.push_back(std::move(newBlock));
217-
blockCapacities.push_back(capacity);
218214
currentBlockIndex = memoryBlocks.size() - 1;
219215
currentIndex = 0;
220216
}

0 commit comments

Comments
 (0)