Core/GuillotineBinPack: Prevent heap allocation when calling Insert with multiple rectangles

This commit is contained in:
Lynix 2019-09-25 16:18:23 +02:00
parent acc2c072ba
commit 76812510a1
2 changed files with 4 additions and 1 deletions

View File

@ -192,6 +192,7 @@ Nazara Engine:
- Added x and y mouse position to MouseWheelEvent
- Added SimpleTextDrawer::[Get|Set]MaxLineWidth (which does line wrap)
- TypeTag helper struct now includes a Type using
- GuillotineBinPack::Insert overload taking multiple rectangles no longer does a heap allocation
Nazara Development Kit:
- Added ImageWidget (#139)

View File

@ -8,6 +8,7 @@
#include <Nazara/Core/GuillotineBinPack.hpp>
#include <Nazara/Core/Config.hpp>
#include <Nazara/Core/StackVector.hpp>
#include <algorithm>
#include <limits>
#include <Nazara/Core/Debug.hpp>
@ -302,7 +303,8 @@ namespace Nz
bool GuillotineBinPack::Insert(Rectui* rects, bool* flipped, bool* inserted, unsigned int count, bool merge, FreeRectChoiceHeuristic rectChoice, GuillotineSplitHeuristic splitMethod)
{
std::vector<Rectui*> remainingRects(count); // Position of the rectangle
Nz::StackVector<Rectui*> remainingRects = NazaraStackVector(Rectui*, count); // Position of the rectangle
remainingRects.resize(count);
for (unsigned int i = 0; i < count; ++i)
remainingRects[i] = &rects[i];