Skip to content

Commit

Permalink
0033670: Coding - TopExp_Explorer performance update
Browse files Browse the repository at this point in the history
Reorganized Explorer memory behavior
  • Loading branch information
dpasukhi committed Dec 20, 2024
1 parent 1dfcac2 commit ee381e2
Showing 1 changed file with 10 additions and 24 deletions.
34 changes: 10 additions & 24 deletions src/TopExp/TopExp_Explorer.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ TopExp_Explorer::TopExp_Explorer()
toAvoid (TopAbs_SHAPE),
hasMore (Standard_False)
{
myStack = (TopoDS_Iterator*)Standard::Allocate(theStackSize*sizeof(TopoDS_Iterator));
myStack = (TopoDS_Iterator*)Standard::AllocateOptimal(theStackSize*sizeof(TopoDS_Iterator));
}

//=======================================================================
Expand All @@ -60,7 +60,7 @@ TopExp_Explorer::TopExp_Explorer (const TopoDS_Shape& theS,
toAvoid (theToAvoid),
hasMore (Standard_False)
{
myStack = (TopoDS_Iterator*)Standard::Allocate(theStackSize*sizeof(TopoDS_Iterator));
myStack = (TopoDS_Iterator*)Standard::AllocateOptimal(theStackSize*sizeof(TopoDS_Iterator));

Init (theS, theToFind, theToAvoid);
}
Expand Down Expand Up @@ -138,7 +138,7 @@ const TopoDS_Shape& TopExp_Explorer::Current()const
void TopExp_Explorer::Next()
{
Standard_Integer NewSize;
TopoDS_Shape ShapTop;
TopoDS_Shape const* ShapTop = nullptr;
TopAbs_ShapeEnum ty;
Standard_NoMoreObject_Raise_if(!hasMore,"TopExp_Explorer::Next");

Expand All @@ -159,16 +159,9 @@ void TopExp_Explorer::Next()
else {
// push and try to find
if(++myTop >= mySizeOfStack) {
NewSize = mySizeOfStack + theStackSize;
TopExp_Stack newStack = (TopoDS_Iterator*)Standard::Allocate(NewSize*sizeof(TopoDS_Iterator));
Standard_Integer i;
for ( i =0; i < myTop; i++) {
new (&newStack[i]) TopoDS_Iterator(myStack[i]);
myStack[i].~TopoDS_Iterator();
}
Standard::Free(myStack);
mySizeOfStack = NewSize;
myStack = newStack;
NewSize = mySizeOfStack + theStackSize;
myStack = (TopoDS_Iterator*)Standard::Reallocate(myStack, NewSize * sizeof(TopoDS_Iterator));
mySizeOfStack = NewSize;
}
new (&myStack[myTop]) TopoDS_Iterator(myShape);
}
Expand All @@ -177,26 +170,19 @@ void TopExp_Explorer::Next()

for (;;) {
if (myStack[myTop].More()) {
ShapTop = myStack[myTop].Value();
ty = ShapTop.ShapeType();
ShapTop = &myStack[myTop].Value();
ty = ShapTop->ShapeType();
if (SAMETYPE(toFind,ty)) {
hasMore = Standard_True;
return;
}
else if (LESSCOMPLEX(toFind,ty) && !AVOID(toAvoid,ty)) {
if(++myTop >= mySizeOfStack) {
NewSize = mySizeOfStack + theStackSize;
TopExp_Stack newStack = (TopoDS_Iterator*)Standard::Allocate(NewSize*sizeof(TopoDS_Iterator));
Standard_Integer i;
for (i =0; i < myTop; i++) {
new (&newStack[i]) TopoDS_Iterator(myStack[i]);
myStack[i].~TopoDS_Iterator();
}
Standard::Free(myStack);
myStack = (TopoDS_Iterator*)Standard::Reallocate(myStack, NewSize * sizeof(TopoDS_Iterator));
mySizeOfStack = NewSize;
myStack = newStack;
}
new (&myStack[myTop]) TopoDS_Iterator(ShapTop);
new (&myStack[myTop]) TopoDS_Iterator(*ShapTop);
}
else {
myStack[myTop].Next();
Expand Down

0 comments on commit ee381e2

Please sign in to comment.