Adapt code
- Reformatting based on clang-format rules - Add usage of size_t instead of unsigned int for sizes - Fix typo in namingpull/3085/head
parent
c91d3764ca
commit
788f2f244e
|
@ -4,7 +4,6 @@ Open Asset Import Library (assimp)
|
||||||
|
|
||||||
Copyright (c) 2006-2020, assimp team
|
Copyright (c) 2006-2020, assimp team
|
||||||
|
|
||||||
|
|
||||||
All rights reserved.
|
All rights reserved.
|
||||||
|
|
||||||
Redistribution and use of this software in source and binary forms,
|
Redistribution and use of this software in source and binary forms,
|
||||||
|
@ -57,89 +56,82 @@ namespace Assimp {
|
||||||
/** \brief Small vector with inplace storage. Reduces heap allocations when list is shorter
|
/** \brief Small vector with inplace storage. Reduces heap allocations when list is shorter
|
||||||
than initial capasity
|
than initial capasity
|
||||||
*/
|
*/
|
||||||
template<typename T, unsigned int Capasity>
|
template<typename T, unsigned int Capacity>
|
||||||
class SmallVector
|
class SmallVector {
|
||||||
{
|
|
||||||
public:
|
public:
|
||||||
SmallVector()
|
SmallVector() :
|
||||||
: mStorage(mInplaceStorage)
|
mStorage(mInplaceStorage),
|
||||||
, mSize(0)
|
mSize(0),
|
||||||
, mCapasity(Capasity)
|
mCapacity(Capasity) {
|
||||||
{
|
// empty
|
||||||
}
|
}
|
||||||
|
|
||||||
~SmallVector()
|
~SmallVector() {
|
||||||
{
|
|
||||||
if (mStorage != mInplaceStorage) {
|
if (mStorage != mInplaceStorage) {
|
||||||
delete [] mStorage;
|
delete [] mStorage;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void push_back(const T& item)
|
void push_back(const T& item) {
|
||||||
{
|
if (mSize < mCapacity) {
|
||||||
if (mSize < mCapasity) {
|
|
||||||
mStorage[mSize++] = item;
|
mStorage[mSize++] = item;
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
else push_back_and_grow(item);
|
|
||||||
|
push_back_and_grow(item);
|
||||||
}
|
}
|
||||||
|
|
||||||
void resize(unsigned int newSize)
|
void resize(unsigned int newSize) {
|
||||||
{
|
if (newSize > mCapacity) {
|
||||||
if (newSize > mCapasity)
|
|
||||||
grow(newSize);
|
grow(newSize);
|
||||||
|
}
|
||||||
mSize = newSize;
|
mSize = newSize;
|
||||||
}
|
}
|
||||||
|
|
||||||
unsigned int size() const
|
size_t size() const {
|
||||||
{
|
|
||||||
return mSize;
|
return mSize;
|
||||||
}
|
}
|
||||||
|
|
||||||
T* begin()
|
T* begin() {
|
||||||
{
|
|
||||||
return mStorage;
|
return mStorage;
|
||||||
}
|
}
|
||||||
|
|
||||||
T* end()
|
T* end() {
|
||||||
{
|
|
||||||
return &mStorage[mSize];
|
return &mStorage[mSize];
|
||||||
}
|
}
|
||||||
|
|
||||||
T* begin() const
|
T* begin() const {
|
||||||
{
|
|
||||||
return mStorage;
|
return mStorage;
|
||||||
}
|
}
|
||||||
|
|
||||||
T* end() const
|
T* end() const {
|
||||||
{
|
|
||||||
return &mStorage[mSize];
|
return &mStorage[mSize];
|
||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void grow(unsigned int newCapasity)
|
void grow( size_t newCapacity) {
|
||||||
{
|
T* oldStorage = mStorage;
|
||||||
T* pOldStorage = mStorage;
|
T* newStorage = new T[newCapacity];
|
||||||
T* pNewStorage = new T[newCapasity];
|
|
||||||
|
|
||||||
std::memcpy(pNewStorage, pOldStorage, mSize * sizeof(T));
|
std::memcpy(newStorage, oldStorage, mSize * sizeof(T));
|
||||||
|
|
||||||
mStorage = pNewStorage;
|
mStorage = newStorage;
|
||||||
mCapasity = newCapasity;
|
mCapacity = newCapacity;
|
||||||
|
|
||||||
if (pOldStorage != mInplaceStorage)
|
if (oldStorage != mInplaceStorage) {
|
||||||
delete [] pOldStorage;
|
delete [] oldStorage;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void push_back_and_grow(const T& item)
|
void push_back_and_grow(const T& item) {
|
||||||
{
|
grow(mCapacity + Capacity);
|
||||||
grow(mCapasity + Capasity);
|
|
||||||
|
|
||||||
mStorage[mSize++] = item;
|
mStorage[mSize++] = item;
|
||||||
}
|
}
|
||||||
|
|
||||||
T* mStorage;
|
T* mStorage;
|
||||||
unsigned int mSize;
|
size_t mSize;
|
||||||
unsigned int mCapasity;
|
size_t mCapacity;
|
||||||
T mInplaceStorage[Capasity];
|
T mInplaceStorage[Capasity];
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue