0024911: Avoid using virtual functions in NCollection classes

NCollection_BaseCollection class, relevant header files, and macro DEFINE_BASECOLLECTION removed.
Hence methods Assign() from other compatible (via inheritance of BaseCollection) collections are not available any more, as well as base Iterator class.

All methods of Iterator classes are made non-virtual, allowing their inline expansion for better performance.

OCCT-specific operators new and delete added to collection classes and removed from iterator classes.
This commit is contained in:
abv
2014-05-08 09:13:00 +04:00
committed by apn
parent 598fcce93c
commit ddf2fe8eeb
66 changed files with 456 additions and 1016 deletions

View File

@@ -17,15 +17,11 @@
#define NCollection_BaseVector_HeaderFile
#include <Standard_TypeDef.hxx>
#include <NCollection_BaseAllocator.hxx>
#include <stddef.h>
#include <Standard_OutOfRange.hxx>
#include <NCollection_BaseAllocator.hxx>
#include <NCollection_DefineAlloc.hxx>
#if defined(_MSC_VER)
#pragma warning(push, 1)
#pragma warning(disable:4355)
#endif
#include <stddef.h>
// this value defines the number of blocks that are reserved
// when the capacity of vector is increased
@@ -37,6 +33,10 @@ inline Standard_Integer GetCapacity (const Standard_Integer theIncrement)
//! Class NCollection_BaseVector - base for NCollection_Vector template
class NCollection_BaseVector
{
public:
//! Memory allocation
DEFINE_STANDARD_ALLOC
DEFINE_NCOLLECTION_ALLOC
protected:
@@ -112,14 +112,14 @@ protected:
}
}
virtual void offsetV (Standard_Integer theOffset)
void offsetV (Standard_Integer theOffset)
{
const Standard_Integer anIndex = myCurIndex + myICurBlock * myVector->myIncrement + theOffset;
myICurBlock = anIndex / myVector->myIncrement;
myCurIndex = anIndex % myVector->myIncrement;
}
virtual Standard_Integer differV (const Iterator& theOther) const
Standard_Integer differV (const Iterator& theOther) const
{
return (myCurIndex - theOther.myCurIndex) + (myICurBlock - theOther.myICurBlock) * myVector->myIncrement;
}
@@ -144,19 +144,17 @@ protected: //! @name Block initializer
const Standard_Integer theSize);
//! Allocate memory for array of memory blocks.
//! @param theAllocator Memory allocator to use
//! @param theCapacity Number of memory blocks in array
//! @param theSource Original array of memory blocks, will be automatically deallocated
//! @param theSourceSize Number of memory blocks in original array
Standard_EXPORT static MemBlock* allocMemBlocks (Handle(NCollection_BaseAllocator)& theAllocator,
const Standard_Integer theCapacity,
MemBlock* theSource = NULL,
const Standard_Integer theSourceSize = 0);
Standard_EXPORT MemBlock* allocMemBlocks (const Standard_Integer theCapacity,
MemBlock* theSource = NULL,
const Standard_Integer theSourceSize = 0);
protected: //! @name protected methods
//! Empty constructor
NCollection_BaseVector (Handle(NCollection_BaseAllocator)& theAllocator,
NCollection_BaseVector (const Handle(NCollection_BaseAllocator)& theAllocator,
initMemBlocks_t theInitBlocks,
const size_t theSize,
const Standard_Integer theInc)
@@ -165,11 +163,14 @@ protected: //! @name protected methods
myLength (0),
myCapacity (GetCapacity (myIncrement)),
myNBlocks (0),
myData (allocMemBlocks (theAllocator, myCapacity)),
myInitBlocks (theInitBlocks) {}
myInitBlocks (theInitBlocks)
{
myAllocator = (theAllocator.IsNull() ? NCollection_BaseAllocator::CommonBaseAllocator() : theAllocator);
myData = allocMemBlocks (myCapacity);
}
//! Copy constructor
NCollection_BaseVector (Handle(NCollection_BaseAllocator)& theAllocator,
NCollection_BaseVector (const Handle(NCollection_BaseAllocator)& theAllocator,
initMemBlocks_t theInitBlocks,
const NCollection_BaseVector& theOther)
: myItemSize (theOther.myItemSize),
@@ -177,12 +178,14 @@ protected: //! @name protected methods
myLength (theOther.myLength),
myCapacity (GetCapacity(myIncrement) + theOther.myLength / theOther.myIncrement),
myNBlocks (1 + (theOther.myLength - 1)/theOther.myIncrement),
myData (allocMemBlocks (theAllocator, myCapacity)),
myInitBlocks (theInitBlocks) {}
myInitBlocks (theInitBlocks)
{
myAllocator = (theAllocator.IsNull() ? NCollection_BaseAllocator::CommonBaseAllocator() : theAllocator);
myData = allocMemBlocks (myCapacity);
}
//! @return pointer to memory where to put the new item
Standard_EXPORT void* expandV (Handle(NCollection_BaseAllocator)& theAllocator,
const Standard_Integer theIndex);
Standard_EXPORT void* expandV (const Standard_Integer theIndex);
//! Locate the memory holding the desired value
inline void* findV (const Standard_Integer theIndex) const
@@ -198,8 +201,9 @@ public: //! @name public API
//! Empty the vector of its objects
Standard_EXPORT void Clear();
protected: //! @name Private fields
protected: //! @name Protected fields
Handle(NCollection_BaseAllocator) myAllocator;
size_t myItemSize;
Standard_Integer myIncrement;
Standard_Integer myLength;
@@ -211,11 +215,6 @@ protected: //! @name Private fields
protected:
friend class Iterator;
};
#if defined(_MSC_VER)
#pragma warning(pop)
#endif
#endif // NCollection_BaseVector_HeaderFile