Collections const-correctness fix

This commit is contained in:
Mateusz Karbowiak
2024-10-30 21:06:16 +01:00
parent c0a1563402
commit 02db7d02f2
6 changed files with 26 additions and 26 deletions

View File

@@ -22,12 +22,12 @@ private:
int32 _capacity;
AllocationData _allocation;
FORCE_INLINE static int32 ToItemCount(int32 size)
FORCE_INLINE static int32 ToItemCount(const int32 size)
{
return Math::DivideAndRoundUp<int32>(size, sizeof(ItemType));
}
FORCE_INLINE static int32 ToItemCapacity(int32 size)
FORCE_INLINE static int32 ToItemCapacity(const int32 size)
{
return Math::Max<int32>(Math::DivideAndRoundUp<int32>(size, sizeof(ItemType)), 1);
}
@@ -46,7 +46,7 @@ public:
/// Initializes a new instance of the <see cref="BitArray"/> class.
/// </summary>
/// <param name="capacity">The initial capacity.</param>
BitArray(int32 capacity)
BitArray(const int32 capacity)
: _count(0)
, _capacity(capacity)
{
@@ -200,7 +200,7 @@ public:
/// </summary>
/// <param name="index">The index of the item.</param>
/// <returns>The value of the item.</returns>
FORCE_INLINE bool operator[](int32 index) const
FORCE_INLINE bool operator[](const int32 index) const
{
return Get(index);
}
@@ -210,7 +210,7 @@ public:
/// </summary>
/// <param name="index">The index of the item.</param>
/// <returns>The value of the item.</returns>
bool Get(int32 index) const
bool Get(const int32 index) const
{
ASSERT(index >= 0 && index < _count);
const ItemType offset = index / sizeof(ItemType);
@@ -224,7 +224,7 @@ public:
/// </summary>
/// <param name="index">The index of the item.</param>
/// <param name="value">The value to set.</param>
void Set(int32 index, bool value)
void Set(const int32 index, const bool value)
{
ASSERT(index >= 0 && index < _count);
const ItemType offset = index / sizeof(ItemType);
@@ -250,7 +250,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;
@@ -266,7 +266,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)
EnsureCapacity(size, preserveContents);
@@ -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, bool preserveContents = true)
void EnsureCapacity(int32 minCapacity, const bool preserveContents = true)
{
if (_capacity < minCapacity)
{
@@ -313,7 +313,7 @@ public:
/// </summary>
/// <param name="items">The items to add.</param>
/// <param name="count">The items count.</param>
void Add(const bool* items, int32 count)
void Add(const bool* items, const int32 count)
{
EnsureCapacity(_count + count);
for (int32 i = 0; i < count; i++)

View File

@@ -149,7 +149,7 @@ public:
/// Initializes a new instance of the <see cref="Dictionary"/> class.
/// </summary>
/// <param name="capacity">The initial capacity.</param>
Dictionary(int32 capacity)
Dictionary(const int32 capacity)
{
SetCapacity(capacity);
}
@@ -538,7 +538,7 @@ public:
/// </summary>
/// <param name="capacity">The new capacity.</param>
/// <param name="preserveContents">Enables preserving collection contents during resizing.</param>
void SetCapacity(int32 capacity, bool preserveContents = true)
void SetCapacity(int32 capacity, const bool preserveContents = true)
{
if (capacity == Capacity())
return;
@@ -598,7 +598,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, bool preserveContents = true)
void EnsureCapacity(int32 minCapacity, const bool preserveContents = true)
{
if (_size >= minCapacity)
return;

View File

@@ -130,7 +130,7 @@ public:
/// Initializes a new instance of the <see cref="HashSet"/> class.
/// </summary>
/// <param name="capacity">The initial capacity.</param>
HashSet(int32 capacity)
HashSet(const int32 capacity)
{
SetCapacity(capacity);
}
@@ -415,7 +415,7 @@ public:
/// </summary>
/// <param name="capacity">New capacity</param>
/// <param name="preserveContents">Enable/disable preserving collection contents during resizing</param>
void SetCapacity(int32 capacity, bool preserveContents = true)
void SetCapacity(int32 capacity, const bool preserveContents = true)
{
if (capacity == Capacity())
return;
@@ -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, bool preserveContents = true)
void EnsureCapacity(int32 minCapacity, const bool preserveContents = true)
{
if (_size >= minCapacity)
return;

View File

@@ -75,13 +75,13 @@ public:
return _allocation.Get()[_front];
}
FORCE_INLINE T& operator[](int32 index)
FORCE_INLINE T& operator[](const int32 index)
{
ASSERT(index >= 0 && index < _count);
return _allocation.Get()[(_front + index) % _capacity];
}
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()[(_front + index) % _capacity];

View File

@@ -39,20 +39,20 @@ public:
return (T*)_data;
}
FORCE_INLINE int32 CalculateCapacityGrow(int32 capacity, int32 minCapacity) const
FORCE_INLINE int32 CalculateCapacityGrow(int32 capacity, const int32 minCapacity) const
{
ASSERT(minCapacity <= Capacity);
return Capacity;
}
FORCE_INLINE void Allocate(int32 capacity)
FORCE_INLINE void Allocate(const int32 capacity)
{
#if ENABLE_ASSERTION_LOW_LAYERS
ASSERT(capacity <= Capacity);
#endif
}
FORCE_INLINE void Relocate(int32 capacity, int32 oldCount, int32 newCount)
FORCE_INLINE void Relocate(const int32 capacity, int32 oldCount, int32 newCount)
{
#if ENABLE_ASSERTION_LOW_LAYERS
ASSERT(capacity <= Capacity);
@@ -104,7 +104,7 @@ public:
return _data;
}
FORCE_INLINE int32 CalculateCapacityGrow(int32 capacity, int32 minCapacity) const
FORCE_INLINE int32 CalculateCapacityGrow(int32 capacity, const int32 minCapacity) const
{
if (capacity < minCapacity)
capacity = minCapacity;
@@ -129,7 +129,7 @@ public:
return capacity;
}
FORCE_INLINE void Allocate(int32 capacity)
FORCE_INLINE void Allocate(const int32 capacity)
{
#if ENABLE_ASSERTION_LOW_LAYERS
ASSERT(!_data);
@@ -141,7 +141,7 @@ public:
#endif
}
FORCE_INLINE void Relocate(int32 capacity, int32 oldCount, int32 newCount)
FORCE_INLINE void Relocate(const int32 capacity, int32 oldCount, int32 newCount)
{
T* newData = capacity != 0 ? (T*)Allocator::Allocate(capacity * sizeof(T)) : nullptr;
#if !BUILD_RELEASE

View File

@@ -242,7 +242,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;
@@ -365,7 +365,7 @@ private:
return (int32)Platform::InterlockedIncrement(&_count) - 1;
}
FORCE_INLINE static int32 GetMinCapacity(int32 count)
FORCE_INLINE static int32 GetMinCapacity(const int32 count)
{
// Ensure there is a slack for others threads to reduce resize counts in highly multi-threaded environment
constexpr int32 slack = PLATFORM_THREADS_LIMIT * 8;