Skip to content

Commit e8ddabd

Browse files
committed
Foundation Classes - Update and Optimize NCollection_Map #140
- Updated Map to store insert order to improve iteration procedure. - Fixed linked list management in NCollection_Map. - Fixed MapNode constructor parameter order and improved null checks. - Ensured Next pointer is set to nullptr when no placement is provided in NCollection_Map. - Simplified More() method in NCollection_Map to only check for nullptr. - Optimized Exchange method in NCollection_Map to swap first and last pointers. - Added resetSize method and enhanced Destroy method in NCollection_Map for better memory management.
1 parent 3d6c211 commit e8ddabd

File tree

6 files changed

+223
-100
lines changed

6 files changed

+223
-100
lines changed

src/BOPAlgo/BOPAlgo_PaveFiller_3.cxx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,6 @@ void BOPAlgo_PaveFiller::PerformEE(const Message_ProgressRange& theRange)
173173
BOPDS_ListIteratorOfListOfPaveBlock aIt1, aIt2;
174174
Handle(NCollection_BaseAllocator) aAllocator;
175175
BOPAlgo_VectorOfEdgeEdge aVEdgeEdge;
176-
BOPDS_MapIteratorOfMapOfPaveBlock aItPB;
177176
// keep modified edges for further update
178177
TColStd_MapOfInteger aMEdges;
179178
//

src/BRepTest/BRepTest_CheckCommands.cxx

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -81,10 +81,12 @@ Standard_EXPORT void BRepTest_CheckCommands_SetFaultyName(const char* name)
8181
}
8282
}
8383

84-
85-
static TopTools_DataMapOfShapeListOfShape theMap;
86-
static Standard_Integer nbfaulty = 0;
87-
static Draw_SequenceOfDrawable3D lfaulty;
84+
namespace
85+
{
86+
static TopTools_DataMapOfShapeListOfShape theMap;
87+
static Standard_Integer nbfaulty = 0;
88+
static Draw_SequenceOfDrawable3D lfaulty;
89+
}
8890

8991
Standard_IMPORT Standard_Integer BRepCheck_Trace(const Standard_Integer phase);
9092

src/NCollection/NCollection_BaseMap.cxx

Lines changed: 37 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -71,13 +71,47 @@ void NCollection_BaseMap::EndResize
7171
myData2 = data2;
7272
}
7373

74+
//=======================================================================
75+
//function : Reallocate
76+
//purpose :
77+
//=======================================================================
78+
Standard_Boolean NCollection_BaseMap::Reallocate(const Standard_Integer theNbBuckets)
79+
{
80+
// get next size for the buckets array
81+
Standard_Integer aNewBuckets = NCollection_Primes::NextPrimeForMap(theNbBuckets);
82+
if (aNewBuckets <= myNbBuckets)
83+
{
84+
if (!myData1)
85+
{
86+
aNewBuckets = myNbBuckets;
87+
}
88+
else
89+
{
90+
return Standard_False;
91+
}
92+
}
93+
myNbBuckets = aNewBuckets;
94+
const size_t aSize = myNbBuckets + 1;
95+
myData1 = (NCollection_ListNode**)Standard::Reallocate(myData1, aSize * sizeof(NCollection_ListNode*));
96+
memset(myData1, 0, aSize * sizeof(NCollection_ListNode*));
97+
if (isDouble)
98+
{
99+
myData2 = (NCollection_ListNode**)Standard::Reallocate(myData2, aSize * sizeof(NCollection_ListNode*));
100+
memset(myData2, 0, aSize * sizeof(NCollection_ListNode*));
101+
}
102+
else
103+
{
104+
myData2 = nullptr;
105+
}
106+
return Standard_True;
107+
}
108+
74109
//=======================================================================
75110
//function : Destroy
76-
//purpose :
111+
//purpose :
77112
//=======================================================================
78113

79-
void NCollection_BaseMap::Destroy (NCollection_DelMapNode fDel,
80-
Standard_Boolean doReleaseMemory)
114+
void NCollection_BaseMap::Destroy(NCollection_DelMapNode fDel, Standard_Boolean doReleaseMemory)
81115
{
82116
if (!IsEmpty())
83117
{

src/NCollection/NCollection_BaseMap.hxx

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -200,6 +200,12 @@ public:
200200
NCollection_ListNode** data1,
201201
NCollection_ListNode** data2);
202202

203+
//! Reallocate the existed data containers.
204+
//! Filling operation must to be done outside.
205+
//! Reallocated memory will be cleared (all elements will be set to nullptr).
206+
Standard_EXPORT Standard_Boolean Reallocate
207+
(const Standard_Integer theNbBuckets);
208+
203209
//! Resizable
204210
Standard_Boolean Resizable() const
205211
{ return IsEmpty() || (mySize > myNbBuckets); }
@@ -243,6 +249,8 @@ public:
243249
NCollection_ListNode ** myData1;
244250
NCollection_ListNode ** myData2;
245251

252+
void resetSize() { mySize = 0; }
253+
246254
private:
247255
// ---------- PRIVATE FIELDS ------------
248256
Standard_Integer myNbBuckets;

0 commit comments

Comments
 (0)