Memory management hygiene: Use compare() instead of substr(), and put a few more things intrinsically in the memory pool.
git-svn-id: https://cvs.khronos.org/svn/repos/ogl/trunk/ecosystem/public/sdk/tools/glslang@23467 e7fa87d3-cd2b-0410-9028-fcbf551c1848
This commit is contained in:
parent
3afe67dcc2
commit
4c70685382
10 changed files with 45 additions and 41 deletions
|
|
@ -91,7 +91,7 @@ namespace glslang {
|
|||
// Pool version of string.
|
||||
//
|
||||
typedef pool_allocator<char> TStringAllocator;
|
||||
typedef std::basic_string <char, std::char_traits<char>, TStringAllocator > TString;
|
||||
typedef std::basic_string <char, std::char_traits<char>, TStringAllocator> TString;
|
||||
inline TString* NewPoolTString(const char* s)
|
||||
{
|
||||
void* memory = GetThreadPoolAllocator().allocate(sizeof(TString));
|
||||
|
|
@ -103,6 +103,8 @@ inline TString* NewPoolTString(const char* s)
|
|||
//
|
||||
template <class T> class TVector : public std::vector<T, pool_allocator<T> > {
|
||||
public:
|
||||
POOL_ALLOCATOR_NEW_DELETE(GetThreadPoolAllocator())
|
||||
|
||||
typedef typename std::vector<T, pool_allocator<T> >::size_type size_type;
|
||||
TVector() : std::vector<T, pool_allocator<T> >() {}
|
||||
TVector(const pool_allocator<T>& a) : std::vector<T, pool_allocator<T> >(a) {}
|
||||
|
|
|
|||
|
|
@ -421,19 +421,20 @@ class TConstUnionArray {
|
|||
public:
|
||||
POOL_ALLOCATOR_NEW_DELETE(GetThreadPoolAllocator())
|
||||
|
||||
TConstUnionArray() { unionArray = 0; }
|
||||
TConstUnionArray() : unionArray(0) { }
|
||||
virtual ~TConstUnionArray() { }
|
||||
|
||||
explicit TConstUnionArray(int size)
|
||||
{
|
||||
if (size == 0)
|
||||
unionArray = 0;
|
||||
else
|
||||
unionArray = new TVector<TConstUnion>(size);
|
||||
unionArray = new TConstUnionVector(size);
|
||||
}
|
||||
TConstUnionArray(const TConstUnionArray& a) : unionArray(a.unionArray) { }
|
||||
TConstUnionArray(const TConstUnionArray& a, int start, int size)
|
||||
{
|
||||
unionArray = new TVector<TConstUnion>(size);
|
||||
unionArray = new TConstUnionVector(size);
|
||||
for (int i = 0; i < size; ++i)
|
||||
(*unionArray)[i] = a[start + i];
|
||||
}
|
||||
|
|
@ -441,7 +442,7 @@ public:
|
|||
// Use this constructor for a smear operation
|
||||
TConstUnionArray(int size, const TConstUnion& val)
|
||||
{
|
||||
unionArray = new TVector<TConstUnion>(size, val);
|
||||
unionArray = new TConstUnionVector(size, val);
|
||||
}
|
||||
|
||||
TConstUnion& operator[](int index) { return (*unionArray)[index]; }
|
||||
|
|
@ -462,7 +463,8 @@ public:
|
|||
bool empty() const { return unionArray == 0; }
|
||||
|
||||
protected:
|
||||
TVector<TConstUnion>* unionArray;
|
||||
typedef TVector<TConstUnion> TConstUnionVector;
|
||||
TConstUnionVector* unionArray;
|
||||
};
|
||||
|
||||
} // end namespace glslang
|
||||
|
|
|
|||
|
|
@ -150,20 +150,8 @@ struct TTypeLoc {
|
|||
};
|
||||
typedef TVector<TTypeLoc> TTypeList;
|
||||
|
||||
inline TTypeList* NewPoolTTypeList()
|
||||
{
|
||||
void* memory = GetThreadPoolAllocator().allocate(sizeof(TTypeList));
|
||||
return new(memory) TTypeList;
|
||||
}
|
||||
|
||||
typedef TVector<TString*> TIdentifierList;
|
||||
|
||||
inline TIdentifierList* NewPoolTIdentifierList()
|
||||
{
|
||||
void* memory = GetThreadPoolAllocator().allocate(sizeof(TIdentifierList));
|
||||
return new(memory) TIdentifierList;
|
||||
}
|
||||
|
||||
//
|
||||
// TODO: memory: TArraySizes can be replaced by something smaller.
|
||||
// Almost all arrays could be handled by two sizes each fitting
|
||||
|
|
@ -175,6 +163,8 @@ inline TIdentifierList* NewPoolTIdentifierList()
|
|||
// is used, it will be containing at least one size.
|
||||
|
||||
struct TArraySizes {
|
||||
POOL_ALLOCATOR_NEW_DELETE(GetThreadPoolAllocator())
|
||||
|
||||
TArraySizes() : maxArraySize(0) { }
|
||||
int getSize() { return sizes.front(); } // TArraySizes only exists if there is at least one dimension
|
||||
void setSize(int s) { sizes.push_back(s); }
|
||||
|
|
@ -185,12 +175,6 @@ protected:
|
|||
int maxArraySize; // for tracking maximum referenced index, before an explicit size is given
|
||||
};
|
||||
|
||||
inline TArraySizes* NewPoolTArraySizes()
|
||||
{
|
||||
void* memory = GetThreadPoolAllocator().allocate(sizeof(TArraySizes));
|
||||
return new(memory) TArraySizes;
|
||||
}
|
||||
|
||||
//
|
||||
// TPublicType (coming up after some dependent declarations)
|
||||
// is a workaround for a problem with the yacc stack, It can't have
|
||||
|
|
@ -484,12 +468,12 @@ public:
|
|||
shallowCopy(copyOf);
|
||||
|
||||
if (arraySizes) {
|
||||
arraySizes = NewPoolTArraySizes();
|
||||
arraySizes = new TArraySizes;
|
||||
*arraySizes = *copyOf.arraySizes;
|
||||
}
|
||||
|
||||
if (structure) {
|
||||
structure = NewPoolTTypeList();
|
||||
structure = new TTypeList;
|
||||
TStructureMapIterator iter;
|
||||
for (unsigned int i = 0; i < copyOf.structure->size(); ++i) {
|
||||
TTypeLoc typeLoc;
|
||||
|
|
@ -604,7 +588,7 @@ public:
|
|||
void setArraySizes(TArraySizes* s)
|
||||
{
|
||||
// For when we don't want distinct types sharing the same descriptor.
|
||||
arraySizes = NewPoolTArraySizes();
|
||||
arraySizes = new TArraySizes;
|
||||
*arraySizes = *s;
|
||||
}
|
||||
void setArraySizes(const TType& type) { setArraySizes(type.arraySizes); }
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue