Skip to content

Commit

Permalink
#5660: Avoid tens of thousands of reallocations of the Face/FaceInsta…
Browse files Browse the repository at this point in the history
…nce vectors when parsing brushes
  • Loading branch information
codereader committed Jul 2, 2021
1 parent 4f9fd03 commit e2bd362
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 33 deletions.
2 changes: 2 additions & 0 deletions radiantcore/brush/Brush.cpp
Expand Up @@ -46,6 +46,8 @@ Brush::Brush(BrushNode& owner) :
m_transformChanged(false),
_detailFlag(Structural)
{
// Make some space for a few faces
reserve(6);
onFacePlaneChanged();
}

Expand Down
8 changes: 6 additions & 2 deletions radiantcore/brush/BrushNode.cpp
Expand Up @@ -21,6 +21,9 @@ BrushNode::BrushNode() :
_untransformedOriginChanged(true)
{
m_brush.attach(*this); // BrushObserver

// Try to anticipate a few face additions to avoid reallocations during map parsing
reserve(6);
}

// Copy Constructor
Expand Down Expand Up @@ -297,8 +300,9 @@ void BrushNode::reserve(std::size_t size) {
m_faceInstances.reserve(size);
}

void BrushNode::push_back(Face& face) {
m_faceInstances.push_back(FaceInstance(face, std::bind(&BrushNode::selectedChangedComponent, this, std::placeholders::_1)));
void BrushNode::push_back(Face& face)
{
m_faceInstances.emplace_back(face, std::bind(&BrushNode::selectedChangedComponent, this, std::placeholders::_1));
_untransformedOriginChanged = true;
}

Expand Down
31 changes: 0 additions & 31 deletions radiantcore/brush/FaceInstance.h
Expand Up @@ -159,34 +159,3 @@ class FaceInstance

typedef std::vector<FaceInstance> FaceInstances;

/*class FaceInstanceSet
{
typedef SelectionList<FaceInstance> FaceInstances;
FaceInstances m_faceInstances;
public:
void insert(FaceInstance& faceInstance) {
m_faceInstances.append(faceInstance);
}
void erase(FaceInstance& faceInstance) {
m_faceInstances.erase(faceInstance);
}
template<typename Functor>
void foreach(Functor& functor) {
for (FaceInstances::iterator i = m_faceInstances.begin(); i != m_faceInstances.end(); ++i) {
functor(*(*i));
}
}
bool empty() const {
return m_faceInstances.empty();
}
FaceInstance& last() const {
return m_faceInstances.back();
}
std::size_t size() const {
return m_faceInstances.size();
}
};*/

0 comments on commit e2bd362

Please sign in to comment.