From: Pasukhin Dmitry Date: Sat, 12 Jul 2025 19:05:55 +0000 (+0100) Subject: Foundation Classes - Optimize NCollection_Array1 with type specific (#608) X-Git-Url: http://git.dev.opencascade.org/gitweb/?a=commitdiff_plain;h=313630c282c724a3fa442c50ac7a857a52ee485a;p=occt.git 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 --- diff --git a/src/FoundationClasses/TKernel/NCollection/NCollection_Array1.hxx b/src/FoundationClasses/TKernel/NCollection/NCollection_Array1.hxx index a051bfd0b6..6659d8d13b 100644 --- a/src/FoundationClasses/TKernel/NCollection/NCollection_Array1.hxx +++ b/src/FoundationClasses/TKernel/NCollection/NCollection_Array1.hxx @@ -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(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(aNewSize, anOldSize); + const size_t aMinSize = std::min(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,30 +396,17 @@ protected: protected: template - typename std::enable_if::value, void>::type construct() + typename std::enable_if::value, void>::type construct( + const size_t, + const size_t) { // Do nothing } template - typename std::enable_if::value, void>::type construct() - { - for (size_t anInd = 0; anInd < mySize; anInd++) - { - myAllocator.construct(myPointer + anInd); - } - } - - template - typename std::enable_if::value, void>::type construct(const size_t, - const size_t) - { - // Do nothing - } - - template - typename std::enable_if::value, void>::type construct(const size_t theFrom, - const size_t theTo) + typename std::enable_if::value, void>::type construct( + const size_t theFrom, + const size_t theTo) { for (size_t anInd = theFrom; anInd < theTo; anInd++) { @@ -429,32 +415,19 @@ protected: } template - typename std::enable_if::value, void>::type destroy() - { - // Do nothing - } - - template - typename std::enable_if::value, void>::type destroy() - { - for (size_t anInd = 0; anInd < mySize; anInd++) - { - myAllocator.destroy(myPointer + anInd); - } - } - - template - typename std::enable_if::value, void>::type destroy(pointer, - const size_t, - const size_t) + typename std::enable_if::value, void>::type destroy( + pointer, + const size_t, + const size_t) { // Do nothing } template - typename std::enable_if::value, void>::type destroy(pointer theWhat, - const size_t theFrom, - const size_t theTo) + typename std::enable_if::value, void>::type destroy( + pointer theWhat, + const size_t theFrom, + const size_t theTo) { for (size_t anInd = theFrom; anInd < theTo; anInd++) {