diff --git a/AK/DisjointChunks.h b/AK/DisjointChunks.h index d58ed43f7e4..181ab1b88ae 100644 --- a/AK/DisjointChunks.h +++ b/AK/DisjointChunks.h @@ -6,6 +6,7 @@ #pragma once +#include #include #include #include @@ -124,7 +125,10 @@ public: return size; } - bool is_empty() const { return size() == 0; } + bool is_empty() const + { + return all_of(m_spans, [](auto& span) { return span.is_empty(); }); + } DisjointSpans slice(size_t start, size_t length) const { @@ -256,7 +260,10 @@ public: return sum; } - bool is_empty() const { return m_chunks.size() == 0 || size() == 0; } + bool is_empty() const + { + return all_of(m_chunks, [](auto& chunk) { return chunk.is_empty(); }); + } DisjointSpans spans() const& { diff --git a/Tests/AK/TestDisjointChunks.cpp b/Tests/AK/TestDisjointChunks.cpp index e8897d2a151..94f052bf9e2 100644 --- a/Tests/AK/TestDisjointChunks.cpp +++ b/Tests/AK/TestDisjointChunks.cpp @@ -13,8 +13,11 @@ TEST_CASE(basic) { DisjointChunks chunks; + EXPECT(chunks.is_empty()); chunks.append({}); + EXPECT(chunks.is_empty()); chunks.last_chunk().append(0); + EXPECT(!chunks.is_empty()); chunks.append({}); chunks.last_chunk().append(1); chunks.last_chunk().append(2);