1
0
mirror of https://git.dev.opencascade.org/repos/occt.git synced 2025-06-30 12:14:08 +03:00

Coding, Data Exchange - Optimize entity graph evaluating #562

Updated the Evaluate() function to integrate memory pool usage and streamline the evaluation loop.
Simplified shared entity retrieval in GetShareds() and Sharings().
Added necessary include for NCollection_IncAllocator to support memory pooling.
This commit is contained in:
Pasukhin Dmitry 2025-05-30 16:11:22 +01:00 committed by GitHub
parent 4629ee0ca3
commit 9ddcdae3f9
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -22,6 +22,7 @@
#include <Interface_ShareTool.hxx> #include <Interface_ShareTool.hxx>
#include <Standard_DomainError.hxx> #include <Standard_DomainError.hxx>
#include <Standard_Transient.hxx> #include <Standard_Transient.hxx>
#include <NCollection_IncAllocator.hxx>
#include <TCollection_HAsciiString.hxx> #include <TCollection_HAsciiString.hxx>
#include <TColStd_HSequenceOfTransient.hxx> #include <TColStd_HSequenceOfTransient.hxx>
#include <TColStd_ListIteratorOfListOfInteger.hxx> #include <TColStd_ListIteratorOfListOfInteger.hxx>
@ -136,42 +137,76 @@ const Handle(TColStd_HArray1OfListOfInteger)& Interface_Graph::SharingTable() co
void Interface_Graph::Evaluate() void Interface_Graph::Evaluate()
{ {
// Evaluation d un Graphe de dependances : sur chaque Entite, on prend sa // Evaluation is performed on all entities of the model
// liste "Shared". On en deduit les "Sharing" directement const Standard_Integer anEntityNumber = Size();
Standard_Integer n = Size();
// clang-format off
thesharings = new TColStd_HArray1OfListOfInteger(1,n);//TColStd_HArray1OfTransient(1,n);//Clear();
// clang-format on
if (themodel->GTool().IsNull())
return;
Standard_Integer i; // svv Jan11 2000 : porting on DEC // Global allocator stored as a field of the single container of the sharings
for (i = 1; i <= n; i++) // and will be destructed with the container.
Handle(NCollection_IncAllocator) anAlloc =
new NCollection_IncAllocator(NCollection_IncAllocator::THE_DEFAULT_BLOCK_SIZE);
thesharings = new TColStd_HArray1OfListOfInteger(1, anEntityNumber);
TColStd_Array1OfListOfInteger& aSharingArrayOfLists = thesharings->ChangeArray1();
for (Standard_Integer i = 1; i <= anEntityNumber; i++)
{ {
// ATTENTION : Si Entite non chargee donc illisible, basculer sur son aSharingArrayOfLists(i).Clear(anAlloc);
// "Contenu" equivalent }
Handle(Standard_Transient) ent = themodel->Value(i);
// Resultat obtenu via GeneralLib if (themodel->GTool().IsNull())
Interface_EntityIterator iter = GetShareds(ent); {
return;
}
// Mise en forme : liste d entiers // Fill the sharing table with the entities shared by each entity
for (iter.Start(); iter.More(); iter.Next()) // and the entities which share each entity.
// The entities are iterated in the order of their numbers in the model.
// The entities which are not present in the model are ignored.
// The entities which are not shared by any other entity are ignored.
// Allocator is used to reuse memory for the lists of shared entities.
Handle(NCollection_IncAllocator) anAlloc2 =
new NCollection_IncAllocator(NCollection_IncAllocator::THE_MINIMUM_BLOCK_SIZE);
Handle(TColStd_HSequenceOfTransient) aListOfEntities = new TColStd_HSequenceOfTransient();
for (Standard_Integer i = 1; i <= anEntityNumber; i++)
{
aListOfEntities->Clear(anAlloc2);
anAlloc2->Reset();
const Handle(Standard_Transient)& anEntity = themodel->Value(i);
Interface_EntityIterator anIter(aListOfEntities);
const Standard_Integer aNumber = EntityNumber(anEntity);
if (aNumber == 0)
{ {
// num = 0 -> on sort du Model de depart, le noter "Error" et passer continue;
const Handle(Standard_Transient)& entshare = iter.Value(); }
if (entshare == ent)
continue;
Standard_Integer num = EntityNumber(entshare); Handle(Standard_Transient) aCurEnt = anEntity;
if (themodel->IsRedefinedContent(aNumber))
aCurEnt = themodel->ReportEntity(aNumber)->Content();
if (!num) Handle(Interface_GeneralModule) aModule;
Standard_Integer aCN;
if (themodel->GTool()->Select(aCurEnt, aModule, aCN))
{
aModule->FillShared(themodel, aCN, aCurEnt, anIter);
}
for (anIter.Start(); anIter.More(); anIter.Next())
{
const Handle(Standard_Transient)& anEntShare = anIter.Value();
if (anEntShare == anEntity)
{ {
if (!thestats.IsNull())
theflags.SetTrue(i, Graph_ShareError);
continue; continue;
} }
thesharings->ChangeValue(num).Append(i);
const Standard_Integer aShareNum = EntityNumber(anEntShare);
if (aShareNum == 0)
{
if (!thestats.IsNull())
{
theflags.SetTrue(i, Graph_ShareError);
}
continue;
}
aSharingArrayOfLists(aShareNum).Append(i);
} }
} }
} }
@ -456,11 +491,7 @@ Interface_EntityIterator Interface_Graph::Shareds(const Handle(Standard_Transien
Handle(TColStd_HSequenceOfTransient) Interface_Graph::GetShareds( Handle(TColStd_HSequenceOfTransient) Interface_Graph::GetShareds(
const Handle(Standard_Transient)& ent) const const Handle(Standard_Transient)& ent) const
{ {
Handle(TColStd_HSequenceOfTransient) aseq = new TColStd_HSequenceOfTransient; return Shareds(ent).Content();
Interface_EntityIterator iter = Shareds(ent);
for (; iter.More(); iter.Next())
aseq->Append(iter.Value());
return aseq;
} }
Handle(TColStd_HSequenceOfTransient) Interface_Graph::GetSharings( Handle(TColStd_HSequenceOfTransient) Interface_Graph::GetSharings(
@ -480,9 +511,7 @@ Handle(TColStd_HSequenceOfTransient) Interface_Graph::GetSharings(
Interface_EntityIterator Interface_Graph::Sharings(const Handle(Standard_Transient)& ent) const Interface_EntityIterator Interface_Graph::Sharings(const Handle(Standard_Transient)& ent) const
{ {
Interface_EntityIterator iter; return Interface_EntityIterator(GetSharings(ent));
iter.AddList(GetSharings(ent));
return iter;
} }
static void AddTypedSharings(const Handle(Standard_Transient)& ent, static void AddTypedSharings(const Handle(Standard_Transient)& ent,