Collections casts fix
This commit is contained in:
@@ -66,7 +66,7 @@ public:
|
||||
/// <param name="initList">The initial values defined in the array.</param>
|
||||
Array(std::initializer_list<T> initList)
|
||||
{
|
||||
_count = _capacity = (int32)initList.size();
|
||||
_count = _capacity = static_cast<int32>(initList.size());
|
||||
if (_count > 0)
|
||||
{
|
||||
_allocation.Allocate(_count);
|
||||
@@ -160,8 +160,8 @@ public:
|
||||
Clear();
|
||||
if (initList.size() > 0)
|
||||
{
|
||||
EnsureCapacity((int32)initList.size());
|
||||
_count = (int32)initList.size();
|
||||
EnsureCapacity(static_cast<int32>(initList.size()));
|
||||
_count = static_cast<int32>(initList.size());
|
||||
Memory::ConstructItems(_allocation.Get(), initList.begin(), _count);
|
||||
}
|
||||
return *this;
|
||||
|
||||
@@ -214,8 +214,8 @@ public:
|
||||
{
|
||||
ASSERT(index >= 0 && index < _count);
|
||||
const ItemType offset = index / sizeof(ItemType);
|
||||
const ItemType bitMask = (ItemType)(int32)(1 << (index & ((int32)sizeof(ItemType) - 1)));
|
||||
const ItemType item = ((ItemType*)_allocation.Get())[offset];
|
||||
const ItemType bitMask = static_cast<ItemType>((int32)(1 << (index & (static_cast<int32>(sizeof(ItemType)) - 1))));
|
||||
const ItemType item = static_cast<ItemType*>(_allocation.Get())[offset];
|
||||
return (item & bitMask) != 0;
|
||||
}
|
||||
|
||||
@@ -228,8 +228,8 @@ public:
|
||||
{
|
||||
ASSERT(index >= 0 && index < _count);
|
||||
const ItemType offset = index / sizeof(ItemType);
|
||||
const ItemType bitMask = (ItemType)(int32)(1 << (index & ((int32)sizeof(ItemType) - 1)));
|
||||
ItemType& item = ((ItemType*)_allocation.Get())[offset];
|
||||
const ItemType bitMask = static_cast<ItemType>((int32)(1 << (index & (static_cast<int32>(sizeof(ItemType)) - 1))));
|
||||
ItemType& item = reinterpret_cast<ItemType*>(_allocation.Get())[offset];
|
||||
if (value)
|
||||
item |= bitMask;
|
||||
else
|
||||
|
||||
@@ -498,7 +498,7 @@ public:
|
||||
FindPosition(key, pos);
|
||||
if (pos.ObjectIndex == -1)
|
||||
return nullptr;
|
||||
return (ValueType*)&_allocation.Get()[pos.ObjectIndex].Value;
|
||||
return static_cast<ValueType*>(&_allocation.Get()[pos.ObjectIndex].Value);
|
||||
}
|
||||
|
||||
public:
|
||||
|
||||
@@ -31,12 +31,12 @@ public:
|
||||
|
||||
FORCE_INLINE T* Get()
|
||||
{
|
||||
return (T*)_data;
|
||||
return reinterpret_cast<T*>(_data);
|
||||
}
|
||||
|
||||
FORCE_INLINE const T* Get() const
|
||||
{
|
||||
return (T*)_data;
|
||||
return reinterpret_cast<const T*>(_data);
|
||||
}
|
||||
|
||||
FORCE_INLINE int32 CalculateCapacityGrow(int32 capacity, const int32 minCapacity) const
|
||||
@@ -134,7 +134,7 @@ public:
|
||||
#if ENABLE_ASSERTION_LOW_LAYERS
|
||||
ASSERT(!_data);
|
||||
#endif
|
||||
_data = (T*)Allocator::Allocate(capacity * sizeof(T));
|
||||
_data = static_cast<T*>(Allocator::Allocate(capacity * sizeof(T)));
|
||||
#if !BUILD_RELEASE
|
||||
if (!_data)
|
||||
OUT_OF_MEMORY;
|
||||
@@ -143,7 +143,7 @@ public:
|
||||
|
||||
FORCE_INLINE void Relocate(const int32 capacity, int32 oldCount, int32 newCount)
|
||||
{
|
||||
T* newData = capacity != 0 ? (T*)Allocator::Allocate(capacity * sizeof(T)) : nullptr;
|
||||
T* newData = capacity != 0 ? static_cast<T*>(Allocator::Allocate(capacity * sizeof(T))) : nullptr;
|
||||
#if !BUILD_RELEASE
|
||||
if (!newData && capacity != 0)
|
||||
OUT_OF_MEMORY;
|
||||
@@ -203,12 +203,12 @@ public:
|
||||
|
||||
FORCE_INLINE T* Get()
|
||||
{
|
||||
return _useOther ? _other.Get() : (T*)_data;
|
||||
return _useOther ? _other.Get() : reinterpret_cast<T*>(_data);
|
||||
}
|
||||
|
||||
FORCE_INLINE const T* Get() const
|
||||
{
|
||||
return _useOther ? _other.Get() : (T*)_data;
|
||||
return _useOther ? _other.Get() : reinterpret_cast<const T*>(_data);
|
||||
}
|
||||
|
||||
FORCE_INLINE int32 CalculateCapacityGrow(int32 capacity, int32 minCapacity) const
|
||||
@@ -227,13 +227,15 @@ public:
|
||||
|
||||
FORCE_INLINE void Relocate(int32 capacity, int32 oldCount, int32 newCount)
|
||||
{
|
||||
T* data = reinterpret_cast<T*>(_data);
|
||||
|
||||
// Check if the new allocation will fit into inlined storage
|
||||
if (capacity <= Capacity)
|
||||
{
|
||||
if (_useOther)
|
||||
{
|
||||
// Move the items from other allocation to the inlined storage
|
||||
Memory::MoveItems((T*)_data, _other.Get(), newCount);
|
||||
Memory::MoveItems(data, _other.Get(), newCount);
|
||||
|
||||
// Free the other allocation
|
||||
Memory::DestructItems(_other.Get(), oldCount);
|
||||
@@ -255,8 +257,8 @@ public:
|
||||
_useOther = true;
|
||||
|
||||
// Move the items from the inlined storage to the other allocation
|
||||
Memory::MoveItems(_other.Get(), (T*)_data, newCount);
|
||||
Memory::DestructItems((T*)_data, oldCount);
|
||||
Memory::MoveItems(_other.Get(), data, newCount);
|
||||
Memory::DestructItems(data, oldCount);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -76,7 +76,7 @@ public:
|
||||
if (_capacity > 0)
|
||||
{
|
||||
_allocation.Allocate(_capacity);
|
||||
Memory::ConstructItems(_allocation.Get(), other.Get(), (int32)other._count);
|
||||
Memory::ConstructItems(_allocation.Get(), other.Get(), static_cast<int32>(other._count));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -102,7 +102,7 @@ public:
|
||||
{
|
||||
if (this != &other)
|
||||
{
|
||||
Memory::DestructItems(_allocation.Get(), (int32)_count);
|
||||
Memory::DestructItems(_allocation.Get(), static_cast<int32>(_count));
|
||||
if (_capacity < other.Count())
|
||||
{
|
||||
_allocation.Free();
|
||||
@@ -110,7 +110,7 @@ public:
|
||||
_allocation.Allocate(_capacity);
|
||||
}
|
||||
_count = other.Count();
|
||||
Memory::ConstructItems(_allocation.Get(), other.Get(), (int32)_count);
|
||||
Memory::ConstructItems(_allocation.Get(), other.Get(), static_cast<int32>(_count));
|
||||
}
|
||||
return *this;
|
||||
}
|
||||
@@ -124,7 +124,7 @@ public:
|
||||
{
|
||||
if (this != &other)
|
||||
{
|
||||
Memory::DestructItems(_allocation.Get(), (int32)_count);
|
||||
Memory::DestructItems(_allocation.Get(), static_cast<int32>(_count));
|
||||
_allocation.Free();
|
||||
_count = other._count;
|
||||
_capacity = other._capacity;
|
||||
@@ -140,7 +140,7 @@ public:
|
||||
/// </summary>
|
||||
~RenderListBuffer()
|
||||
{
|
||||
Memory::DestructItems(_allocation.Get(), (int32)_count);
|
||||
Memory::DestructItems(_allocation.Get(), static_cast<int32>(_count));
|
||||
}
|
||||
|
||||
public:
|
||||
@@ -149,7 +149,7 @@ public:
|
||||
/// </summary>
|
||||
FORCE_INLINE int32 Count() const
|
||||
{
|
||||
return (int32)Platform::AtomicRead((volatile int64*)&_count);
|
||||
return static_cast<int32>(Platform::AtomicRead((volatile int64*)&_count));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -157,7 +157,7 @@ public:
|
||||
/// </summary>
|
||||
FORCE_INLINE int32 Capacity() const
|
||||
{
|
||||
return (int32)Platform::AtomicRead((volatile int64*)&_capacity);
|
||||
return static_cast<int32>(Platform::AtomicRead((volatile int64*)&_capacity));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -232,7 +232,7 @@ public:
|
||||
void Clear()
|
||||
{
|
||||
_locker.Lock();
|
||||
Memory::DestructItems(_allocation.Get(), (int32)_count);
|
||||
Memory::DestructItems(_allocation.Get(), static_cast<int32>(_count));
|
||||
_count = 0;
|
||||
_locker.Unlock();
|
||||
}
|
||||
@@ -248,8 +248,8 @@ public:
|
||||
return;
|
||||
_locker.Lock();
|
||||
ASSERT(capacity >= 0);
|
||||
const int32 count = preserveContents ? ((int32)_count < capacity ? (int32)_count : capacity) : 0;
|
||||
_allocation.Relocate(capacity, (int32)_count, count);
|
||||
const int32 count = preserveContents ? (static_cast<int32>(_count) < capacity ? static_cast<int32>(_count) : capacity) : 0;
|
||||
_allocation.Relocate(capacity, static_cast<int32>(_count), count);
|
||||
Platform::AtomicStore(&_capacity, capacity);
|
||||
Platform::AtomicStore(&_count, count);
|
||||
_locker.Unlock();
|
||||
@@ -265,12 +265,12 @@ public:
|
||||
_locker.Lock();
|
||||
if (_count > size)
|
||||
{
|
||||
Memory::DestructItems(_allocation.Get() + size, (int32)_count - size);
|
||||
Memory::DestructItems(_allocation.Get() + size, static_cast<int32>(_count) - size);
|
||||
}
|
||||
else
|
||||
{
|
||||
EnsureCapacity(size, preserveContents);
|
||||
Memory::ConstructItems(_allocation.Get() + _count, size - (int32)_count);
|
||||
Memory::ConstructItems(_allocation.Get() + _count, size - static_cast<int32>(_count));
|
||||
}
|
||||
_count = size;
|
||||
_locker.Unlock();
|
||||
@@ -283,11 +283,11 @@ public:
|
||||
void EnsureCapacity(int32 minCapacity)
|
||||
{
|
||||
_locker.Lock();
|
||||
int32 capacity = (int32)Platform::AtomicRead(&_capacity);
|
||||
int32 capacity = static_cast<int32>(Platform::AtomicRead(&_capacity));
|
||||
if (capacity < minCapacity)
|
||||
{
|
||||
capacity = _allocation.CalculateCapacityGrow(capacity, minCapacity);
|
||||
const int32 count = (int32)_count;
|
||||
const int32 count = static_cast<int32>(_count);
|
||||
_allocation.Relocate(capacity, count, count);
|
||||
Platform::AtomicStore(&_capacity, capacity);
|
||||
}
|
||||
@@ -324,8 +324,8 @@ private:
|
||||
int32 AddOne()
|
||||
{
|
||||
Platform::InterlockedIncrement(&_threadsAdding);
|
||||
int32 count = (int32)Platform::AtomicRead(&_count);
|
||||
int32 capacity = (int32)Platform::AtomicRead(&_capacity);
|
||||
int32 count = static_cast<int32>(Platform::AtomicRead(&_count));
|
||||
int32 capacity = static_cast<int32>(Platform::AtomicRead(&_capacity));
|
||||
const int32 minCapacity = GetMinCapacity(count);
|
||||
if (minCapacity > capacity || Platform::AtomicRead(&_threadsResizing)) // Resize if not enough space or someone else is already doing it (don't add mid-resizing)
|
||||
{
|
||||
@@ -340,7 +340,7 @@ private:
|
||||
|
||||
// Thread-safe resizing
|
||||
_locker.Lock();
|
||||
capacity = (int32)Platform::AtomicRead(&_capacity);
|
||||
capacity = static_cast<int32>(Platform::AtomicRead(&_capacity));
|
||||
if (capacity < minCapacity)
|
||||
{
|
||||
if (Platform::AtomicRead(&_threadsAdding))
|
||||
@@ -350,7 +350,7 @@ private:
|
||||
goto RETRY;
|
||||
}
|
||||
capacity = _allocation.CalculateCapacityGrow(capacity, minCapacity);
|
||||
count = (int32)Platform::AtomicRead(&_count);
|
||||
count = static_cast<int32>(Platform::AtomicRead(&_count));
|
||||
_allocation.Relocate(capacity, count, count);
|
||||
Platform::AtomicStore(&_capacity, capacity);
|
||||
}
|
||||
@@ -362,7 +362,7 @@ private:
|
||||
// Let other thread enter resizing-area
|
||||
_locker.Unlock();
|
||||
}
|
||||
return (int32)Platform::InterlockedIncrement(&_count) - 1;
|
||||
return static_cast<int32>(Platform::InterlockedIncrement(&_count)) - 1;
|
||||
}
|
||||
|
||||
FORCE_INLINE static int32 GetMinCapacity(const int32 count)
|
||||
|
||||
Reference in New Issue
Block a user