1
0
mirror of https://git.dev.opencascade.org/repos/occt.git synced 2025-08-09 13:22:24 +03:00

0029064: Copying of empty NCollection map takes excessive memory

Avoid resizing of NCollection maps in Assign() methods if source map is empty
This commit is contained in:
isn
2018-01-15 20:29:14 +03:00
committed by bugmaster
parent 8e45500e21
commit 229add784f
7 changed files with 126 additions and 39 deletions

View File

@@ -168,10 +168,14 @@ public:
return *this;
Clear();
ReSize (theOther.Extent()-1);
Iterator anIter(theOther);
for (; anIter.More(); anIter.Next())
Bind (anIter.Key(), anIter.Value());
Standard_Integer anExt = theOther.Extent();
if (anExt)
{
ReSize (anExt-1);
Iterator anIter(theOther);
for (; anIter.More(); anIter.Next())
Bind (anIter.Key(), anIter.Value());
}
return *this;
}

View File

@@ -151,20 +151,24 @@ public:
return *this;
Clear();
ReSize (theOther.Extent()-1);
Iterator anIter(theOther);
for (; anIter.More(); anIter.Next())
Standard_Integer anExt = theOther.Extent();
if (anExt)
{
TheKey1Type aKey1 = anIter.Key1();
TheKey2Type aKey2 = anIter.Key2();
Standard_Integer iK1 = Hasher1::HashCode (aKey1, NbBuckets());
Standard_Integer iK2 = Hasher2::HashCode (aKey2, NbBuckets());
DoubleMapNode * pNode = new (this->myAllocator) DoubleMapNode (aKey1, aKey2,
myData1[iK1],
myData2[iK2]);
myData1[iK1] = pNode;
myData2[iK2] = pNode;
Increment();
ReSize (anExt-1);
Iterator anIter(theOther);
for (; anIter.More(); anIter.Next())
{
TheKey1Type aKey1 = anIter.Key1();
TheKey2Type aKey2 = anIter.Key2();
Standard_Integer iK1 = Hasher1::HashCode (aKey1, NbBuckets());
Standard_Integer iK2 = Hasher2::HashCode (aKey2, NbBuckets());
DoubleMapNode * pNode = new (this->myAllocator) DoubleMapNode (aKey1, aKey2,
myData1[iK1],
myData2[iK2]);
myData1[iK1] = pNode;
myData2[iK2] = pNode;
Increment();
}
}
return *this;
}

View File

@@ -190,16 +190,20 @@ private:
return *this;
Clear();
ReSize (theOther.Extent()-1);
for (Standard_Integer anIndexIter = 1; anIndexIter <= theOther.Extent(); ++anIndexIter)
Standard_Integer anExt = theOther.Extent();
if (anExt)
{
const TheKeyType& aKey1 = theOther.FindKey (anIndexIter);
const TheItemType& anItem = theOther.FindFromIndex(anIndexIter);
const Standard_Integer iK1 = Hasher::HashCode (aKey1, NbBuckets());
IndexedDataMapNode* pNode = new (this->myAllocator) IndexedDataMapNode (aKey1, anIndexIter, anItem, myData1[iK1]);
myData1[iK1] = pNode;
myData2[anIndexIter - 1] = pNode;
Increment();
ReSize (anExt-1); //mySize is same after resize
for (Standard_Integer anIndexIter = 1; anIndexIter <= anExt; ++anIndexIter)
{
const TheKeyType& aKey1 = theOther.FindKey (anIndexIter);
const TheItemType& anItem = theOther.FindFromIndex(anIndexIter);
const Standard_Integer iK1 = Hasher::HashCode (aKey1, NbBuckets());
IndexedDataMapNode* pNode = new (this->myAllocator) IndexedDataMapNode (aKey1, anIndexIter, anItem, myData1[iK1]);
myData1[iK1] = pNode;
myData2[anIndexIter - 1] = pNode;
Increment();
}
}
return *this;
}

View File

@@ -152,16 +152,19 @@ private:
return *this;
Clear();
ReSize (theOther.Extent()-1);
const Standard_Integer iLength = theOther.Extent();
for (Standard_Integer anIndexIter = 1; anIndexIter <= iLength; ++anIndexIter)
Standard_Integer anExt = theOther.Extent();
if (anExt)
{
const TheKeyType& aKey1 = theOther.FindKey (anIndexIter);
const Standard_Integer iK1 = Hasher::HashCode (aKey1, NbBuckets());
IndexedMapNode* pNode = new (this->myAllocator) IndexedMapNode (aKey1, anIndexIter, myData1[iK1]);
myData1[iK1] = pNode;
myData2[anIndexIter - 1] = pNode;
Increment();
ReSize (anExt-1); //mySize is same after resize
for (Standard_Integer anIndexIter = 1; anIndexIter <= anExt; ++anIndexIter)
{
const TheKeyType& aKey1 = theOther.FindKey (anIndexIter);
const Standard_Integer iK1 = Hasher::HashCode (aKey1, NbBuckets());
IndexedMapNode* pNode = new (this->myAllocator) IndexedMapNode (aKey1, anIndexIter, myData1[iK1]);
myData1[iK1] = pNode;
myData2[anIndexIter - 1] = pNode;
Increment();
}
}
return *this;
}

View File

@@ -147,10 +147,14 @@ public:
return *this;
Clear();
ReSize (theOther.Extent()-1);
Iterator anIter(theOther);
for (; anIter.More(); anIter.Next())
Add (anIter.Key());
int anExt = theOther.Extent();
if (anExt)
{
ReSize (anExt-1);
Iterator anIter(theOther);
for (; anIter.More(); anIter.Next())
Add (anIter.Key());
}
return *this;
}