mirror of
https://git.dev.opencascade.org/repos/occt.git
synced 2025-07-15 12:35:51 +03:00
Foundation Classes - Optimize NCollection_Array1 with type specific (#608)
- Replaced parameterless `construct()` and `destroy()` methods with parameterized versions that specify ranges - Updated type trait checks from `is_arithmetic` to `is_trivially_default_constructible` and `is_trivially_destructible` - Removed redundant local variable `anOldSize` in the `Resize` method
This commit is contained in:
parent
08f6de3aff
commit
313630c282
@ -111,7 +111,7 @@ public:
|
|||||||
}
|
}
|
||||||
myPointer = myAllocator.allocate(mySize);
|
myPointer = myAllocator.allocate(mySize);
|
||||||
myIsOwner = true;
|
myIsOwner = true;
|
||||||
construct();
|
construct(0, mySize);
|
||||||
}
|
}
|
||||||
|
|
||||||
explicit NCollection_Array1(const allocator_type& theAlloc,
|
explicit NCollection_Array1(const allocator_type& theAlloc,
|
||||||
@ -129,7 +129,7 @@ public:
|
|||||||
}
|
}
|
||||||
myPointer = myAllocator.allocate(mySize);
|
myPointer = myAllocator.allocate(mySize);
|
||||||
myIsOwner = true;
|
myIsOwner = true;
|
||||||
construct();
|
construct(0, mySize);
|
||||||
}
|
}
|
||||||
|
|
||||||
explicit NCollection_Array1(const_reference theBegin,
|
explicit NCollection_Array1(const_reference theBegin,
|
||||||
@ -147,7 +147,7 @@ public:
|
|||||||
}
|
}
|
||||||
myPointer = myAllocator.allocate(mySize);
|
myPointer = myAllocator.allocate(mySize);
|
||||||
myIsOwner = true;
|
myIsOwner = true;
|
||||||
construct();
|
construct(0, mySize);
|
||||||
}
|
}
|
||||||
|
|
||||||
//! Copy constructor
|
//! Copy constructor
|
||||||
@ -180,7 +180,7 @@ public:
|
|||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
destroy();
|
destroy(myPointer, 0, mySize);
|
||||||
myAllocator.deallocate(myPointer, mySize);
|
myAllocator.deallocate(myPointer, mySize);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -238,7 +238,7 @@ public:
|
|||||||
}
|
}
|
||||||
if (myIsOwner)
|
if (myIsOwner)
|
||||||
{
|
{
|
||||||
destroy();
|
destroy(myPointer, 0, mySize);
|
||||||
myAllocator.deallocate(myPointer, mySize);
|
myAllocator.deallocate(myPointer, mySize);
|
||||||
}
|
}
|
||||||
myLowerBound = theOther.myLowerBound;
|
myLowerBound = theOther.myLowerBound;
|
||||||
@ -337,9 +337,8 @@ public:
|
|||||||
{
|
{
|
||||||
Standard_RangeError_Raise_if(theUpper < theLower, "NCollection_Array1::Resize");
|
Standard_RangeError_Raise_if(theUpper < theLower, "NCollection_Array1::Resize");
|
||||||
const size_t aNewSize = static_cast<size_t>(theUpper - theLower + 1);
|
const size_t aNewSize = static_cast<size_t>(theUpper - theLower + 1);
|
||||||
const size_t anOldSize = mySize;
|
|
||||||
pointer aPrevContPnt = myPointer;
|
pointer aPrevContPnt = myPointer;
|
||||||
if (aNewSize == anOldSize)
|
if (aNewSize == mySize)
|
||||||
{
|
{
|
||||||
myLowerBound = theLower;
|
myLowerBound = theLower;
|
||||||
return;
|
return;
|
||||||
@ -349,13 +348,12 @@ public:
|
|||||||
if (theToCopyData)
|
if (theToCopyData)
|
||||||
destroy(myPointer, aNewSize, mySize);
|
destroy(myPointer, aNewSize, mySize);
|
||||||
else
|
else
|
||||||
destroy();
|
destroy(myPointer, 0, mySize);
|
||||||
}
|
}
|
||||||
myLowerBound = theLower;
|
myLowerBound = theLower;
|
||||||
mySize = aNewSize;
|
|
||||||
if (theToCopyData)
|
if (theToCopyData)
|
||||||
{
|
{
|
||||||
const size_t aMinSize = std::min<size_t>(aNewSize, anOldSize);
|
const size_t aMinSize = std::min<size_t>(aNewSize, mySize);
|
||||||
if (myIsOwner)
|
if (myIsOwner)
|
||||||
{
|
{
|
||||||
myPointer = myAllocator.reallocate(myPointer, aNewSize);
|
myPointer = myAllocator.reallocate(myPointer, aNewSize);
|
||||||
@ -365,15 +363,16 @@ public:
|
|||||||
myPointer = myAllocator.allocate(aNewSize);
|
myPointer = myAllocator.allocate(aNewSize);
|
||||||
copyConstruct(aPrevContPnt, aMinSize);
|
copyConstruct(aPrevContPnt, aMinSize);
|
||||||
}
|
}
|
||||||
construct(anOldSize, aNewSize);
|
construct(mySize, aNewSize);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
if (myIsOwner)
|
if (myIsOwner)
|
||||||
myAllocator.deallocate(aPrevContPnt, mySize);
|
myAllocator.deallocate(aPrevContPnt, mySize);
|
||||||
myPointer = myAllocator.allocate(aNewSize);
|
myPointer = myAllocator.allocate(aNewSize);
|
||||||
construct();
|
construct(0, aNewSize);
|
||||||
}
|
}
|
||||||
|
mySize = aNewSize;
|
||||||
myIsOwner = true;
|
myIsOwner = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -397,29 +396,16 @@ protected:
|
|||||||
|
|
||||||
protected:
|
protected:
|
||||||
template <typename U = TheItemType>
|
template <typename U = TheItemType>
|
||||||
typename std::enable_if<std::is_arithmetic<U>::value, void>::type construct()
|
typename std::enable_if<std::is_trivially_default_constructible<U>::value, void>::type construct(
|
||||||
{
|
const size_t,
|
||||||
// Do nothing
|
|
||||||
}
|
|
||||||
|
|
||||||
template <typename U = TheItemType>
|
|
||||||
typename std::enable_if<!std::is_arithmetic<U>::value, void>::type construct()
|
|
||||||
{
|
|
||||||
for (size_t anInd = 0; anInd < mySize; anInd++)
|
|
||||||
{
|
|
||||||
myAllocator.construct(myPointer + anInd);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
template <typename U = TheItemType>
|
|
||||||
typename std::enable_if<std::is_arithmetic<U>::value, void>::type construct(const size_t,
|
|
||||||
const size_t)
|
const size_t)
|
||||||
{
|
{
|
||||||
// Do nothing
|
// Do nothing
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename U = TheItemType>
|
template <typename U = TheItemType>
|
||||||
typename std::enable_if<!std::is_arithmetic<U>::value, void>::type construct(const size_t theFrom,
|
typename std::enable_if<!std::is_trivially_default_constructible<U>::value, void>::type construct(
|
||||||
|
const size_t theFrom,
|
||||||
const size_t theTo)
|
const size_t theTo)
|
||||||
{
|
{
|
||||||
for (size_t anInd = theFrom; anInd < theTo; anInd++)
|
for (size_t anInd = theFrom; anInd < theTo; anInd++)
|
||||||
@ -429,22 +415,8 @@ protected:
|
|||||||
}
|
}
|
||||||
|
|
||||||
template <typename U = TheItemType>
|
template <typename U = TheItemType>
|
||||||
typename std::enable_if<std::is_arithmetic<U>::value, void>::type destroy()
|
typename std::enable_if<std::is_trivially_destructible<U>::value, void>::type destroy(
|
||||||
{
|
pointer,
|
||||||
// Do nothing
|
|
||||||
}
|
|
||||||
|
|
||||||
template <typename U = TheItemType>
|
|
||||||
typename std::enable_if<!std::is_arithmetic<U>::value, void>::type destroy()
|
|
||||||
{
|
|
||||||
for (size_t anInd = 0; anInd < mySize; anInd++)
|
|
||||||
{
|
|
||||||
myAllocator.destroy(myPointer + anInd);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
template <typename U = TheItemType>
|
|
||||||
typename std::enable_if<std::is_arithmetic<U>::value, void>::type destroy(pointer,
|
|
||||||
const size_t,
|
const size_t,
|
||||||
const size_t)
|
const size_t)
|
||||||
{
|
{
|
||||||
@ -452,7 +424,8 @@ protected:
|
|||||||
}
|
}
|
||||||
|
|
||||||
template <typename U = TheItemType>
|
template <typename U = TheItemType>
|
||||||
typename std::enable_if<!std::is_arithmetic<U>::value, void>::type destroy(pointer theWhat,
|
typename std::enable_if<!std::is_trivially_destructible<U>::value, void>::type destroy(
|
||||||
|
pointer theWhat,
|
||||||
const size_t theFrom,
|
const size_t theFrom,
|
||||||
const size_t theTo)
|
const size_t theTo)
|
||||||
{
|
{
|
||||||
|
Loading…
x
Reference in New Issue
Block a user