summaryrefslogtreecommitdiff
path: root/asl/containers
diff options
context:
space:
mode:
Diffstat (limited to 'asl/containers')
-rw-r--r--asl/containers/buffer.hpp9
-rw-r--r--asl/containers/buffer_tests.cpp24
-rw-r--r--asl/containers/hash_map_tests.cpp1
-rw-r--r--asl/containers/hash_set.hpp7
-rw-r--r--asl/containers/hash_set_tests.cpp15
-rw-r--r--asl/containers/intrusive_list.hpp2
-rw-r--r--asl/containers/intrusive_list_tests.cpp2
7 files changed, 32 insertions, 28 deletions
diff --git a/asl/containers/buffer.hpp b/asl/containers/buffer.hpp
index 386b52a..c7fc01f 100644
--- a/asl/containers/buffer.hpp
+++ b/asl/containers/buffer.hpp
@@ -80,7 +80,7 @@ private:
{
return is_on_heap(size_encoded)
? static_cast<isize_t>(size_encoded & (~kOnHeapMask))
- : static_cast<isize_t>(size_encoded >> 56);
+ : static_cast<isize_t>(size_encoded >> 56U);
}
}
@@ -110,7 +110,7 @@ private:
constexpr void set_size_inline(isize_t new_size)
{
ASL_ASSERT(new_size >= 0 && new_size <= kInlineCapacity);
- size_t size_encoded = (load_size_encoded() & size_t{0x00ff'ffff'ffff'ffff}) | (bit_cast<size_t>(new_size) << 56);
+ size_t size_encoded = (load_size_encoded() & size_t{0x00ff'ffff'ffff'ffff}) | (bit_cast<size_t>(new_size) << 56U);
store_size_encoded(size_encoded);
}
@@ -328,12 +328,12 @@ public:
if (currently_on_heap && trivially_move_constructible<T>)
{
- m_data = reinterpret_cast<T*>(m_allocator.realloc(m_data, old_layout, new_layout));
+ m_data = static_cast<T*>(m_allocator.realloc(m_data, old_layout, new_layout));
m_capacity = new_capacity;
return;
}
- T* new_data = reinterpret_cast<T*>(m_allocator.alloc(new_layout));
+ T* new_data = static_cast<T*>(m_allocator.alloc(new_layout));
relocate_uninit_n(new_data, old_data, current_size);
@@ -394,6 +394,7 @@ public:
}
else
{
+ // NOLINTNEXTLINE(*-reinterpret-cast)
return self.is_on_heap() ? return_type{ self.m_data } : reinterpret_cast<return_type>(&self);
}
}
diff --git a/asl/containers/buffer_tests.cpp b/asl/containers/buffer_tests.cpp
index af79c92..2538e92 100644
--- a/asl/containers/buffer_tests.cpp
+++ b/asl/containers/buffer_tests.cpp
@@ -24,7 +24,7 @@ ASL_TEST(default_size)
ASL_TEST_EXPECT(b1.capacity() == 5);
ASL_TEST_EXPECT(static_cast<const void*>(b1.data()) == &b1);
- asl::buffer<Big> b2;
+ const asl::buffer<Big> b2;
ASL_TEST_EXPECT(b2.size() == 0);
ASL_TEST_EXPECT(b2.capacity() == 0);
ASL_TEST_EXPECT(b2.data() == nullptr);
@@ -34,6 +34,7 @@ struct CounterAllocator
{
isize_t* count;
+ [[nodiscard]]
void* alloc(const asl::layout& layout) const
{
*count += 1;
@@ -76,6 +77,7 @@ struct IncompatibleAllocator
};
static_assert(asl::allocator<IncompatibleAllocator>);
+// NOLINTNEXTLINE(*-complexity)
ASL_TEST(reserve_capacity)
{
isize_t count = 0;
@@ -105,6 +107,7 @@ ASL_TEST(reserve_capacity)
ASL_TEST_EXPECT(count == 2);
}
+// NOLINTNEXTLINE(*-complexity)
ASL_TEST(push)
{
asl::buffer<int32_t> b;
@@ -137,7 +140,7 @@ ASL_TEST(push)
ASL_TEST(from_span)
{
- int data[] = {1, 2, 4, 8};
+ const int data[] = {1, 2, 4, 8};
asl::buffer<int> b{data};
ASL_TEST_EXPECT(b.size() == 4);
@@ -157,12 +160,14 @@ struct MoveableType
MoveableType(MoveableType&& other) : moved{other.moved + 1}, value{other.value} {}
MoveableType& operator=(const MoveableType&) = delete;
MoveableType& operator=(MoveableType&&) = delete;
+ ~MoveableType() = default;
};
static_assert(!asl::trivially_copy_constructible<MoveableType>);
static_assert(!asl::trivially_move_constructible<MoveableType>);
static_assert(!asl::copyable<MoveableType>);
static_assert(asl::move_constructible<MoveableType>);
+// NOLINTNEXTLINE(*-complexity)
ASL_TEST(push_move)
{
asl::buffer<MoveableType> b;
@@ -275,14 +280,13 @@ ASL_TEST(move_construct_from_heap)
buf.push(&d[2]);
{
- asl::buffer<DestructorObserver> buf2(std::move(buf));
+ const asl::buffer<DestructorObserver> buf2(std::move(buf));
ASL_TEST_EXPECT(buf2.size() == 3);
ASL_TEST_EXPECT(d[0] == false);
ASL_TEST_EXPECT(d[1] == false);
ASL_TEST_EXPECT(d[2] == false);
}
- ASL_TEST_EXPECT(buf.size() == 0);
ASL_TEST_EXPECT(d[0] == true);
ASL_TEST_EXPECT(d[1] == true);
ASL_TEST_EXPECT(d[2] == true);
@@ -299,7 +303,6 @@ ASL_TEST(move_construct_inline_trivial)
ASL_TEST_EXPECT(buf2[1] == 2U);
ASL_TEST_EXPECT(buf2.size() == 2);
- ASL_TEST_EXPECT(buf.size() == 0);
}
ASL_TEST(move_construct_from_inline_non_trivial)
@@ -310,17 +313,17 @@ ASL_TEST(move_construct_from_inline_non_trivial)
buf.push(&d[1]);
{
- asl::buffer<DestructorObserver> buf2(std::move(buf));
+ const asl::buffer<DestructorObserver> buf2(std::move(buf));
ASL_TEST_EXPECT(buf2.size() == 2);
ASL_TEST_EXPECT(d[0] == false);
ASL_TEST_EXPECT(d[1] == false);
}
- ASL_TEST_EXPECT(buf.size() == 0);
ASL_TEST_EXPECT(d[0] == true);
ASL_TEST_EXPECT(d[1] == true);
}
+// NOLINTNEXTLINE(*-complexity)
ASL_TEST(move_assign_from_heap)
{
bool d[6]{};
@@ -346,7 +349,6 @@ ASL_TEST(move_assign_from_heap)
buf2 = std::move(buf);
- ASL_TEST_EXPECT(buf.size() == 0);
ASL_TEST_EXPECT(buf2.size() == 3);
ASL_TEST_EXPECT(d[0] == false);
@@ -384,7 +386,6 @@ ASL_TEST(move_assign_trivial_heap_to_inline)
ASL_TEST_EXPECT(alloc_count == 1);
ASL_TEST_EXPECT(buf.size() == 3);
- ASL_TEST_EXPECT(buf2.size() == 0);
ASL_TEST_EXPECT(buf[0] == 3);
ASL_TEST_EXPECT(buf[1] == 4);
ASL_TEST_EXPECT(buf[2] == 5);
@@ -408,12 +409,12 @@ ASL_TEST(move_assign_trivial_inline_to_heap)
buf2 = std::move(buf);
ASL_TEST_EXPECT(alloc_count == 1);
- ASL_TEST_EXPECT(buf.size() == 0);
ASL_TEST_EXPECT(buf2.size() == 2);
ASL_TEST_EXPECT(buf2[0] == 1);
ASL_TEST_EXPECT(buf2[1] == 2);
}
+// NOLINTNEXTLINE(*-complexity)
ASL_TEST(move_assign_inline_to_heap)
{
bool d[6]{};
@@ -432,7 +433,6 @@ ASL_TEST(move_assign_inline_to_heap)
buf2 = std::move(buf);
- ASL_TEST_EXPECT(buf.size() == 0);
ASL_TEST_EXPECT(buf2.size() == 2);
ASL_TEST_EXPECT(d[0] == false);
ASL_TEST_EXPECT(d[1] == false);
@@ -450,6 +450,7 @@ ASL_TEST(move_assign_inline_to_heap)
ASL_TEST_EXPECT(d[5] == true);
}
+// NOLINTNEXTLINE(*-complexity)
ASL_TEST(move_assign_from_inline_incompatible_allocator)
{
bool d[6]{};
@@ -468,7 +469,6 @@ ASL_TEST(move_assign_from_inline_incompatible_allocator)
buf2 = std::move(buf);
- ASL_TEST_EXPECT(buf.size() == 0);
ASL_TEST_EXPECT(buf2.size() == 2);
ASL_TEST_EXPECT(d[0] == false);
ASL_TEST_EXPECT(d[1] == false);
diff --git a/asl/containers/hash_map_tests.cpp b/asl/containers/hash_map_tests.cpp
index 9652e2f..fe8a284 100644
--- a/asl/containers/hash_map_tests.cpp
+++ b/asl/containers/hash_map_tests.cpp
@@ -5,6 +5,7 @@
#include "asl/testing/testing.hpp"
#include "asl/containers/hash_map.hpp"
+// NOLINTNEXTLINE(*-complexity)
ASL_TEST(default)
{
asl::hash_map<int, int> map;
diff --git a/asl/containers/hash_set.hpp b/asl/containers/hash_set.hpp
index 61346fa..02a8036 100644
--- a/asl/containers/hash_set.hpp
+++ b/asl/containers/hash_set.hpp
@@ -75,7 +75,7 @@ protected:
constexpr isize_t max_size() const
{
// Max load factor is 75%
- return (m_capacity >> 1) + (m_capacity >> 2);
+ return (m_capacity >> 1) + (m_capacity >> 2); // NOLINT(*-signed-bitwise)
}
static isize_t size_to_capacity(isize_t size)
@@ -131,8 +131,8 @@ protected:
{
ASL_ASSERT(new_capacity >= kMinCapacity && is_pow2(new_capacity) && new_capacity > m_capacity);
- auto* new_tags = reinterpret_cast<uint8_t*>(m_allocator.alloc(layout::array<uint8_t>(new_capacity)));
- auto* new_values = reinterpret_cast<maybe_uninit<T>*>(m_allocator.alloc(layout::array<maybe_uninit<T>>(new_capacity)));
+ auto* new_tags = static_cast<uint8_t*>(m_allocator.alloc(layout::array<uint8_t>(new_capacity)));
+ auto* new_values = static_cast<maybe_uninit<T>*>(m_allocator.alloc(layout::array<maybe_uninit<T>>(new_capacity)));
asl::memzero(new_tags, new_capacity);
isize_t new_size = 0;
@@ -228,7 +228,6 @@ protected:
result.tag = static_cast<uint8_t>(hash & kHashMask) | kHasValue;
// NOLINTBEGIN(*-pointer-arithmetic)
-
for (
isize_t i = starting_index;
i != starting_index || result.first_available_index < 0;
diff --git a/asl/containers/hash_set_tests.cpp b/asl/containers/hash_set_tests.cpp
index 515fe76..8f42e50 100644
--- a/asl/containers/hash_set_tests.cpp
+++ b/asl/containers/hash_set_tests.cpp
@@ -10,7 +10,7 @@
ASL_TEST(empty)
{
- asl::hash_set<int> set;
+ const asl::hash_set<int> set;
ASL_TEST_EXPECT(set.size() == 0);
@@ -42,7 +42,7 @@ ASL_TEST(a_bunch_of_ints)
{
asl::hash_set<int> set;
- int count = 3000;
+ const int count = 3000;
for (int i = 0; i < count; ++i)
{
@@ -98,6 +98,7 @@ struct CustomHasher
}
};
+// NOLINTNEXTLINE(*-complexity)
ASL_TEST(destructor_and_remove)
{
static constexpr int kCount = 200;
@@ -113,9 +114,9 @@ ASL_TEST(destructor_and_remove)
ASL_TEST_EXPECT(set.size() == kCount);
- for (int i = 0; i < kCount; ++i)
+ for (const bool i : destroyed)
{
- ASL_TEST_EXPECT(!destroyed[i]); // NOLINT
+ ASL_TEST_EXPECT(!i); // NOLINT
}
for (int i = 0; i < kCount; i += 2)
@@ -132,9 +133,9 @@ ASL_TEST(destructor_and_remove)
}
}
- for (int i = 0; i < kCount; ++i)
+ for (const bool i : destroyed)
{
- ASL_TEST_EXPECT(destroyed[i]); // NOLINT
+ ASL_TEST_EXPECT(i); // NOLINT
}
}
@@ -147,7 +148,7 @@ ASL_TEST(copy)
set1.insert(i);
}
- asl::hash_set<int> set2 = set1;
+ const asl::hash_set<int> set2 = set1;
asl::hash_set<int> set3;
set3 = set1;
diff --git a/asl/containers/intrusive_list.hpp b/asl/containers/intrusive_list.hpp
index 2af02eb..a58bbfd 100644
--- a/asl/containers/intrusive_list.hpp
+++ b/asl/containers/intrusive_list.hpp
@@ -188,5 +188,5 @@ public:
}
};
-}
+} // namespace asl
diff --git a/asl/containers/intrusive_list_tests.cpp b/asl/containers/intrusive_list_tests.cpp
index 4e19237..146ab6b 100644
--- a/asl/containers/intrusive_list_tests.cpp
+++ b/asl/containers/intrusive_list_tests.cpp
@@ -23,6 +23,7 @@ ASL_TEST(empty_list)
ASL_TEST_EXPECT(list.back() == nullptr);
}
+// NOLINTNEXTLINE(*-complexity)
ASL_TEST(push_front)
{
IntNode one{1};
@@ -75,6 +76,7 @@ ASL_TEST(push_front)
ASL_TEST_ASSERT(it == end);
}
+// NOLINTNEXTLINE(*-complexity)
ASL_TEST(push_back)
{
IntNode one{1};