Collections const correctness fix (style)

This commit is contained in:
Mateusz Karbowiak
2024-10-31 00:29:38 +01:00
parent 66b6a29ed4
commit 9c448f75d8
5 changed files with 34 additions and 34 deletions

View File

@@ -25,7 +25,7 @@ private:
int32 _capacity;
AllocationData _allocation;
FORCE_INLINE static void MoveToEmpty(AllocationData& to, AllocationData& from, int32 fromCount, int32 fromCapacity)
FORCE_INLINE static void MoveToEmpty(AllocationData& to, AllocationData& from, const int32 fromCount, const int32 fromCapacity)
{
if IF_CONSTEXPR (AllocationType::HasSwap)
to.Swap(from);
@@ -52,7 +52,7 @@ public:
/// Initializes a new instance of the <see cref="Array"/> class.
/// </summary>
/// <param name="capacity">The initial capacity.</param>
explicit Array(int32 capacity)
explicit Array(const int32 capacity)
: _count(0)
, _capacity(capacity)
{
@@ -79,7 +79,7 @@ public:
/// </summary>
/// <param name="data">The initial data.</param>
/// <param name="length">The amount of items.</param>
Array(const T* data, int32 length)
Array(const T* data, const int32 length)
{
ASSERT(length >= 0);
_count = _capacity = length;
@@ -255,7 +255,7 @@ public:
/// </summary>
/// <param name="index">The index.</param>
/// <returns><c>true</c> if is valid a index; otherwise, <c>false</c>.</returns>
bool IsValidIndex(int32 index) const
bool IsValidIndex(const int32 index) const
{
return index < _count && index >= 0;
}
@@ -280,7 +280,7 @@ public:
/// Gets item at the given index.
/// </summary>
/// <returns>The reference to the item.</returns>
FORCE_INLINE T& At(int32 index)
FORCE_INLINE T& At(const int32 index)
{
ASSERT(index >= 0 && index < _count);
return _allocation.Get()[index];
@@ -290,7 +290,7 @@ public:
/// Gets item at the given index.
/// </summary>
/// <returns>The reference to the item.</returns>
FORCE_INLINE const T& At(int32 index) const
FORCE_INLINE const T& At(const int32 index) const
{
ASSERT(index >= 0 && index < _count);
return _allocation.Get()[index];
@@ -300,7 +300,7 @@ public:
/// Gets or sets the item at the given index.
/// </summary>
/// <returns>The reference to the item.</returns>
FORCE_INLINE T& operator[](int32 index)
FORCE_INLINE T& operator[](const int32 index)
{
ASSERT(index >= 0 && index < _count);
return _allocation.Get()[index];
@@ -310,7 +310,7 @@ public:
/// Gets the item at the given index.
/// </summary>
/// <returns>The reference to the item.</returns>
FORCE_INLINE const T& operator[](int32 index) const
FORCE_INLINE const T& operator[](const int32 index) const
{
ASSERT(index >= 0 && index < _count);
return _allocation.Get()[index];
@@ -406,7 +406,7 @@ public:
/// </summary>
/// <param name="capacity">The new capacity.</param>
/// <param name="preserveContents">True if preserve collection data when changing its size, otherwise collection after resize will be empty.</param>
void SetCapacity(const int32 capacity, bool preserveContents = true)
void SetCapacity(const int32 capacity, const bool preserveContents = true)
{
if (capacity == _capacity)
return;
@@ -422,7 +422,7 @@ public:
/// </summary>
/// <param name="size">The new collection size.</param>
/// <param name="preserveContents">True if preserve collection data when changing its size, otherwise collection after resize might not contain the previous data.</param>
void Resize(int32 size, bool preserveContents = true)
void Resize(const int32 size, const bool preserveContents = true)
{
if (_count > size)
{
@@ -441,7 +441,7 @@ public:
/// </summary>
/// <param name="minCapacity">The minimum capacity.</param>
/// <param name="preserveContents">True if preserve collection data when changing its size, otherwise collection after resize will be empty.</param>
void EnsureCapacity(int32 minCapacity, bool preserveContents = true)
void EnsureCapacity(const int32 minCapacity, const bool preserveContents = true)
{
if (_capacity < minCapacity)
{
@@ -466,7 +466,7 @@ public:
/// </summary>
/// <param name="data">The data.</param>
/// <param name="count">The amount of items.</param>
void Set(const T* data, int32 count)
void Set(const T* data, const int32 count)
{
EnsureCapacity(count, false);
Memory::DestructItems(_allocation.Get(), _count);
@@ -501,7 +501,7 @@ public:
/// </summary>
/// <param name="items">The items to add.</param>
/// <param name="count">The items count.</param>
void Add(const T* items, int32 count)
void Add(const T* items, const int32 count)
{
EnsureCapacity(_count + count);
Memory::ConstructItems(_allocation.Get() + _count, items, count);
@@ -532,7 +532,7 @@ public:
/// Adds the given amount of items to the collection.
/// </summary>
/// <param name="count">The items count.</param>
FORCE_INLINE void AddDefault(int32 count = 1)
FORCE_INLINE void AddDefault(const int32 count = 1)
{
EnsureCapacity(_count + count);
Memory::ConstructItems(_allocation.Get() + _count, count);
@@ -543,7 +543,7 @@ public:
/// Adds the given amount of uninitialized items to the collection without calling the constructor.
/// </summary>
/// <param name="count">The items count.</param>
FORCE_INLINE void AddUninitialized(int32 count = 1)
FORCE_INLINE void AddUninitialized(const int32 count = 1)
{
EnsureCapacity(_count + count);
_count += count;
@@ -568,7 +568,7 @@ public:
/// Warning! AddZeroed() will create items without calling the constructor and this is not appropriate for item types that require a constructor to function properly.
/// </remarks>
/// <param name="count">The number of new items to add.</param>
void AddZeroed(int32 count = 1)
void AddZeroed(const int32 count = 1)
{
EnsureCapacity(_count + count);
Platform::MemoryClear(_allocation.Get() + _count, count * sizeof(T));
@@ -580,7 +580,7 @@ public:
/// </summary>
/// <param name="index">The zero-based index at which item should be inserted.</param>
/// <param name="item">The item to be inserted by copying.</param>
void Insert(int32 index, const T& item)
void Insert(const int32 index, const T& item)
{
ASSERT(index >= 0 && index <= _count);
EnsureCapacity(_count + 1);
@@ -597,7 +597,7 @@ public:
/// </summary>
/// <param name="index">The zero-based index at which item should be inserted.</param>
/// <param name="item">The item to inserted by moving.</param>
void Insert(int32 index, T&& item)
void Insert(const int32 index, T&& item)
{
ASSERT(index >= 0 && index <= _count);
EnsureCapacity(_count + 1);
@@ -613,7 +613,7 @@ public:
/// Insert the given item at specified index with keeping items order.
/// </summary>
/// <param name="index">The zero-based index at which item should be inserted.</param>
void Insert(int32 index)
void Insert(const int32 index)
{
ASSERT(index >= 0 && index <= _count);
EnsureCapacity(_count + 1);
@@ -954,7 +954,7 @@ public:
{
}
Iterator(Array const* array, const int32 index)
Iterator(const Array* array, const int32 index)
: _array(const_cast<Array*>(array))
, _index(index)
{
@@ -1084,7 +1084,7 @@ public:
};
template<typename T, typename AllocationType>
void* operator new(size_t size, Array<T, AllocationType>& array)
void* operator new(const size_t size, Array<T, AllocationType>& array)
{
ASSERT(size == sizeof(T));
const int32 index = array.Count();
@@ -1093,7 +1093,7 @@ void* operator new(size_t size, Array<T, AllocationType>& array)
}
template<typename T, typename AllocationType>
void* operator new(size_t size, Array<T, AllocationType>& array, int32 index)
void* operator new(const size_t size, Array<T, AllocationType>& array, const int32 index)
{
ASSERT(size == sizeof(T));
array.Insert(index);

View File

@@ -278,7 +278,7 @@ public:
/// </summary>
/// <param name="minCapacity">The minimum capacity.</param>
/// <param name="preserveContents">True if preserve collection data when changing its size, otherwise collection after resize will be empty.</param>
void EnsureCapacity(int32 minCapacity, const bool preserveContents = true)
void EnsureCapacity(const int32 minCapacity, const bool preserveContents = true)
{
if (_capacity < minCapacity)
{

View File

@@ -110,7 +110,7 @@ private:
int32 _size = 0;
AllocationData _allocation;
FORCE_INLINE static void MoveToEmpty(AllocationData& to, AllocationData& from, int32 fromSize)
FORCE_INLINE static void MoveToEmpty(AllocationData& to, AllocationData& from, const int32 fromSize)
{
if IF_CONSTEXPR (AllocationType::HasSwap)
to.Swap(from);

View File

@@ -93,7 +93,7 @@ private:
int32 _size = 0;
AllocationData _allocation;
FORCE_INLINE static void MoveToEmpty(AllocationData& to, AllocationData& from, int32 fromSize)
FORCE_INLINE static void MoveToEmpty(AllocationData& to, AllocationData& from, const int32 fromSize)
{
if IF_CONSTEXPR (AllocationType::HasSwap)
to.Swap(from);
@@ -252,7 +252,7 @@ public:
{
}
Iterator(HashSet const* collection, const int32 index)
Iterator(const HashSet* collection, const int32 index)
: _collection(const_cast<HashSet*>(collection))
, _index(index)
{
@@ -307,7 +307,7 @@ public:
return _index >= 0 && _index < _collection->_size;
}
FORCE_INLINE bool operator !() const
FORCE_INLINE bool operator!() const
{
return !(bool)*this;
}
@@ -474,7 +474,7 @@ public:
/// </summary>
/// <param name="minCapacity">The minimum required capacity.</param>
/// <param name="preserveContents">True if preserve collection data when changing its size, otherwise collection after resize will be empty.</param>
void EnsureCapacity(int32 minCapacity, const bool preserveContents = true)
void EnsureCapacity(const int32 minCapacity, const bool preserveContents = true)
{
if (_size >= minCapacity)
return;

View File

@@ -42,7 +42,7 @@ public:
/// Initializes a new instance of the <see cref="RenderListBuffer"/> class.
/// </summary>
/// <param name="capacity">The initial capacity.</param>
explicit RenderListBuffer(int32 capacity)
explicit RenderListBuffer(const int32 capacity)
: _count(0)
, _capacity(capacity)
{
@@ -55,7 +55,7 @@ public:
/// </summary>
/// <param name="data">The initial data.</param>
/// <param name="length">The amount of items.</param>
RenderListBuffer(const T* data, int32 length)
RenderListBuffer(const T* data, const int32 length)
{
ASSERT(length >= 0);
_count = _capacity = length;
@@ -188,7 +188,7 @@ public:
/// Gets or sets the item at the given index.
/// </summary>
/// <returns>The reference to the item.</returns>
FORCE_INLINE T& operator[](int32 index)
FORCE_INLINE T& operator[](const int32 index)
{
ASSERT(index >= 0 && index < Count());
return _allocation.Get()[index];
@@ -198,7 +198,7 @@ public:
/// Gets the item at the given index.
/// </summary>
/// <returns>The reference to the item.</returns>
FORCE_INLINE const T& operator[](int32 index) const
FORCE_INLINE const T& operator[](const int32 index) const
{
ASSERT(index >= 0 && index < Count());
return _allocation.Get()[index];
@@ -260,7 +260,7 @@ public:
/// </summary>
/// <param name="size">The new collection size.</param>
/// <param name="preserveContents">True if preserve collection data when changing its size, otherwise collection after resize might not contain the previous data.</param>
void Resize(int32 size, bool preserveContents = true)
void Resize(const int32 size, const bool preserveContents = true)
{
_locker.Lock();
if (_count > size)
@@ -280,7 +280,7 @@ public:
/// Ensures the collection has given capacity (or more).
/// </summary>
/// <param name="minCapacity">The minimum capacity.</param>
void EnsureCapacity(int32 minCapacity)
void EnsureCapacity(const int32 minCapacity)
{
_locker.Lock();
int32 capacity = static_cast<int32>(Platform::AtomicRead(&_capacity));