diff options
author | Michel Hermier <michel.hermier@gmail.com> | 2021-12-22 00:34:05 +0100 |
---|---|---|
committer | Brian Gianforcaro <b.gianfo@gmail.com> | 2021-12-24 05:55:34 -0800 |
commit | 4758dac21881cae6f1c7ff6e2257ef63c7eeb402 (patch) | |
tree | b81942c5820c94f880c1ac4c505cf6180cf47f51 /AK | |
parent | 44a6d7968a00f2b70720897d660f1512e3645416 (diff) | |
download | serenity-4758dac21881cae6f1c7ff6e2257ef63c7eeb402.zip |
AK: Make `Disjoint*::is_empty()` not call size
This is a raffinement of 49cbd4dcca037336ad5e2e4fcb1e3cc613b46cce.
Previously, the container was scanned to compute the size in the unhappy
path. Now, using `all_of` happy and unhappy path should be fast.
Diffstat (limited to 'AK')
-rw-r--r-- | AK/DisjointChunks.h | 11 |
1 files changed, 9 insertions, 2 deletions
diff --git a/AK/DisjointChunks.h b/AK/DisjointChunks.h index d58ed43f7e..181ab1b88a 100644 --- a/AK/DisjointChunks.h +++ b/AK/DisjointChunks.h @@ -6,6 +6,7 @@ #pragma once +#include <AK/AllOf.h> #include <AK/Forward.h> #include <AK/Span.h> #include <AK/StdLibExtras.h> @@ -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<T> spans() const& { |