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);
|
||||
myIsOwner = true;
|
||||
construct();
|
||||
construct(0, mySize);
|
||||
}
|
||||
|
||||
explicit NCollection_Array1(const allocator_type& theAlloc,
|
||||
@ -129,7 +129,7 @@ public:
|
||||
}
|
||||
myPointer = myAllocator.allocate(mySize);
|
||||
myIsOwner = true;
|
||||
construct();
|
||||
construct(0, mySize);
|
||||
}
|
||||
|
||||
explicit NCollection_Array1(const_reference theBegin,
|
||||
@ -147,7 +147,7 @@ public:
|
||||
}
|
||||
myPointer = myAllocator.allocate(mySize);
|
||||
myIsOwner = true;
|
||||
construct();
|
||||
construct(0, mySize);
|
||||
}
|
||||
|
||||
//! Copy constructor
|
||||
@ -180,7 +180,7 @@ public:
|
||||
{
|
||||
return;
|
||||
}
|
||||
destroy();
|
||||
destroy(myPointer, 0, mySize);
|
||||
myAllocator.deallocate(myPointer, mySize);
|
||||
}
|
||||
|
||||
@ -238,7 +238,7 @@ public:
|
||||
}
|
||||
if (myIsOwner)
|
||||
{
|
||||
destroy();
|
||||
destroy(myPointer, 0, mySize);
|
||||
myAllocator.deallocate(myPointer, mySize);
|
||||
}
|
||||
myLowerBound = theOther.myLowerBound;
|
||||
@ -337,9 +337,8 @@ public:
|
||||
{
|
||||
Standard_RangeError_Raise_if(theUpper < theLower, "NCollection_Array1::Resize");
|
||||
const size_t aNewSize = static_cast<size_t>(theUpper - theLower + 1);
|
||||
const size_t anOldSize = mySize;
|
||||
pointer aPrevContPnt = myPointer;
|
||||
if (aNewSize == anOldSize)
|
||||
if (aNewSize == mySize)
|
||||
{
|
||||
myLowerBound = theLower;
|
||||
return;
|
||||
@ -349,13 +348,12 @@ public:
|
||||
if (theToCopyData)
|
||||
destroy(myPointer, aNewSize, mySize);
|
||||
else
|
||||
destroy();
|
||||
destroy(myPointer, 0, mySize);
|
||||
}
|
||||
myLowerBound = theLower;
|
||||
mySize = aNewSize;
|
||||
if (theToCopyData)
|
||||
{
|
||||
const size_t aMinSize = std::min<size_t>(aNewSize, anOldSize);
|
||||
const size_t aMinSize = std::min<size_t>(aNewSize, mySize);
|
||||
if (myIsOwner)
|
||||
{
|
||||
myPointer = myAllocator.reallocate(myPointer, aNewSize);
|
||||
@ -365,15 +363,16 @@ public:
|
||||
myPointer = myAllocator.allocate(aNewSize);
|
||||
copyConstruct(aPrevContPnt, aMinSize);
|
||||
}
|
||||
construct(anOldSize, aNewSize);
|
||||
construct(mySize, aNewSize);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (myIsOwner)
|
||||
myAllocator.deallocate(aPrevContPnt, mySize);
|
||||
myPointer = myAllocator.allocate(aNewSize);
|
||||
construct();
|
||||
construct(0, aNewSize);
|
||||
}
|
||||
mySize = aNewSize;
|
||||
myIsOwner = true;
|
||||
}
|
||||
|
||||
@ -397,29 +396,16 @@ protected:
|
||||
|
||||
protected:
|
||||
template <typename U = TheItemType>
|
||||
typename std::enable_if<std::is_arithmetic<U>::value, void>::type construct()
|
||||
{
|
||||
// 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,
|
||||
typename std::enable_if<std::is_trivially_default_constructible<U>::value, void>::type construct(
|
||||
const size_t,
|
||||
const size_t)
|
||||
{
|
||||
// Do nothing
|
||||
}
|
||||
|
||||
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)
|
||||
{
|
||||
for (size_t anInd = theFrom; anInd < theTo; anInd++)
|
||||
@ -429,22 +415,8 @@ protected:
|
||||
}
|
||||
|
||||
template <typename U = TheItemType>
|
||||
typename std::enable_if<std::is_arithmetic<U>::value, void>::type destroy()
|
||||
{
|
||||
// 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,
|
||||
typename std::enable_if<std::is_trivially_destructible<U>::value, void>::type destroy(
|
||||
pointer,
|
||||
const size_t,
|
||||
const size_t)
|
||||
{
|
||||
@ -452,7 +424,8 @@ protected:
|
||||
}
|
||||
|
||||
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 theTo)
|
||||
{
|
||||
|
Loading…
x
Reference in New Issue
Block a user