mirror of
https://github.com/Mauler125/r5sdk.git
synced 2025-02-09 19:15:03 +01:00
Tier1: use template index type for memory allocation
For CUtl* classes: use the index type rather than just ssize_t, this will throw compile warnings for code that constructs a CUtl* object allocating more memory than the index type allows (e.g. allocating UINT16_MAX while the index type has been set to UINT8_MAX).
This commit is contained in:
parent
582ec3791e
commit
f67d8e87b1
@ -192,7 +192,7 @@ template < class T >
|
||||
class CUtlFixedLinkedList : public CUtlLinkedList< T, intptr_t, true, intptr_t, CUtlFixedMemory< UtlLinkedListElem_t< T, intptr_t > > >
|
||||
{
|
||||
public:
|
||||
CUtlFixedLinkedList(ssize_t growSize = 0, ssize_t initSize = 0)
|
||||
CUtlFixedLinkedList(intptr_t growSize = 0, intptr_t initSize = 0)
|
||||
: CUtlLinkedList< T, intptr_t, true, intptr_t, CUtlFixedMemory< UtlLinkedListElem_t< T, intptr_t > > >(growSize, initSize) {}
|
||||
|
||||
bool IsValidIndex(intptr_t i) const
|
||||
|
@ -267,12 +267,12 @@ public:
|
||||
LessFunc_t m_LessFunc;
|
||||
};
|
||||
|
||||
typedef CUtlRBTree<Node_t, I, CKeyLess> CTree;
|
||||
typedef CUtlRBTree<Node_t, IndexType_t, CKeyLess> CTree;
|
||||
|
||||
CTree *AccessTree() { return &m_Tree; }
|
||||
|
||||
protected:
|
||||
CTree m_Tree;
|
||||
CTree m_Tree;
|
||||
};
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
@ -151,11 +151,11 @@ public:
|
||||
// Left at growSize = 0, the memory will first allocate 1 element and double in size
|
||||
// at each increment.
|
||||
// LessFunc_t is required, but may be set after the constructor using SetLessFunc() below
|
||||
CUtlRBTree(ssize_t growSize = 0, ssize_t initSize = 0, const LessFunc_t& lessfunc = 0);
|
||||
CUtlRBTree(IndexType_t growSize = 0, IndexType_t initSize = 0, const LessFunc_t& lessfunc = 0);
|
||||
CUtlRBTree(const LessFunc_t& lessfunc);
|
||||
~CUtlRBTree();
|
||||
|
||||
void EnsureCapacity(ssize_t num);
|
||||
void EnsureCapacity(IndexType_t num);
|
||||
|
||||
// NOTE: CopyFrom is fast but dangerous! It just memcpy's all nodes - it does NOT run copy constructors, so
|
||||
// it is not a true deep copy (i.e 'T' must be POD for this to work - e.g CUtlString will not work).
|
||||
@ -215,7 +215,7 @@ public:
|
||||
// NOTE: the returned 'index' will be valid as long as the element remains in the tree
|
||||
// (other elements being added/removed will not affect it)
|
||||
I Insert(T const& insert);
|
||||
void Insert(const T* pArray, ssize_t nItems);
|
||||
void Insert(const T* pArray, I nItems);
|
||||
I InsertIfNotFound(T const& insert);
|
||||
|
||||
// Find method
|
||||
@ -384,7 +384,7 @@ protected:
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
template < class T, class I, typename L, class M >
|
||||
inline CUtlRBTree<T, I, L, M>::CUtlRBTree(ssize_t growSize, ssize_t initSize, const LessFunc_t& lessfunc) :
|
||||
inline CUtlRBTree<T, I, L, M>::CUtlRBTree(IndexType_t growSize, IndexType_t initSize, const LessFunc_t& lessfunc) :
|
||||
m_LessFunc(lessfunc),
|
||||
m_Elements(growSize, initSize),
|
||||
m_Root(InvalidIndex()),
|
||||
@ -414,7 +414,7 @@ inline CUtlRBTree<T, I, L, M>::~CUtlRBTree()
|
||||
}
|
||||
|
||||
template < class T, class I, typename L, class M >
|
||||
inline void CUtlRBTree<T, I, L, M>::EnsureCapacity(ssize_t num)
|
||||
inline void CUtlRBTree<T, I, L, M>::EnsureCapacity(IndexType_t num)
|
||||
{
|
||||
m_Elements.EnsureCapacity(num);
|
||||
}
|
||||
@ -1509,7 +1509,7 @@ I CUtlRBTree<T, I, L, M>::Insert(T const& insert)
|
||||
|
||||
|
||||
template < class T, class I, typename L, class M >
|
||||
void CUtlRBTree<T, I, L, M>::Insert(const T* pArray, ssize_t nItems)
|
||||
void CUtlRBTree<T, I, L, M>::Insert(const T* pArray, I nItems)
|
||||
{
|
||||
while (nItems--)
|
||||
{
|
||||
|
@ -104,7 +104,7 @@ class CUtlSymbolTable
|
||||
{
|
||||
public:
|
||||
// constructor, destructor
|
||||
CUtlSymbolTable( ssize_t growSize = 0, ssize_t initSize = 16, bool caseInsensitive = false );
|
||||
CUtlSymbolTable( unsigned short growSize = 0, unsigned short initSize = 16, bool caseInsensitive = false );
|
||||
~CUtlSymbolTable();
|
||||
|
||||
// Finds and/or creates a symbol based on the string
|
||||
@ -166,7 +166,7 @@ protected:
|
||||
class CTree : public CUtlRBTree<CStringPoolIndex, unsigned short, CLess>
|
||||
{
|
||||
public:
|
||||
CTree( ssize_t growSize, ssize_t initSize ) : CUtlRBTree<CStringPoolIndex, unsigned short, CLess>( growSize, initSize ) {}
|
||||
CTree( unsigned short growSize, unsigned short initSize ) : CUtlRBTree<CStringPoolIndex, unsigned short, CLess>( growSize, initSize ) {}
|
||||
friend class CUtlSymbolTable::CLess; // Needed to allow CLess to calculate pointer to symbol table
|
||||
};
|
||||
|
||||
@ -193,13 +193,12 @@ private:
|
||||
|
||||
friend class CLess;
|
||||
friend class CSymbolHash;
|
||||
|
||||
};
|
||||
|
||||
class CUtlSymbolTableMT : public CUtlSymbolTable
|
||||
class CUtlSymbolTableMT : public CUtlSymbolTable
|
||||
{
|
||||
public:
|
||||
CUtlSymbolTableMT( ssize_t growSize = 0, ssize_t initSize = 32, bool caseInsensitive = false )
|
||||
CUtlSymbolTableMT( unsigned short growSize = 0, unsigned short initSize = 32, bool caseInsensitive = false )
|
||||
: CUtlSymbolTable( growSize, initSize, caseInsensitive )
|
||||
{
|
||||
}
|
||||
|
@ -228,7 +228,7 @@ int CUtlSymbolTable::CLess::operator()( const CStringPoolIndex &i1, const CStrin
|
||||
//-----------------------------------------------------------------------------
|
||||
// constructor, destructor
|
||||
//-----------------------------------------------------------------------------
|
||||
CUtlSymbolTable::CUtlSymbolTable( ssize_t growSize, ssize_t initSize, bool caseInsensitive ) :
|
||||
CUtlSymbolTable::CUtlSymbolTable( unsigned short growSize, unsigned short initSize, bool caseInsensitive ) :
|
||||
m_Lookup( growSize, initSize ), m_bInsensitive( caseInsensitive ), m_StringPools( 8 ),
|
||||
m_nUserSearchStringHash( 0 ), m_pUserSearchString( nullptr )
|
||||
{
|
||||
|
Loading…
x
Reference in New Issue
Block a user