mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-06-11 18:20:43 +09:00
AK: Make Disjoint*::is_empty()
not call size
This is a raffinement of 49cbd4dcca
.
Previously, the container was scanned to compute the size in the unhappy
path. Now, using `all_of` happy and unhappy path should be fast.
This commit is contained in:
parent
44a6d7968a
commit
4758dac218
Notes:
sideshowbarker
2024-07-17 22:12:46 +09:00
Author: https://github.com/mhermier
Commit: 4758dac218
Pull-request: https://github.com/SerenityOS/serenity/pull/11361
2 changed files with 12 additions and 2 deletions
|
@ -6,6 +6,7 @@
|
||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
|
#include <AK/AllOf.h>
|
||||||
#include <AK/Forward.h>
|
#include <AK/Forward.h>
|
||||||
#include <AK/Span.h>
|
#include <AK/Span.h>
|
||||||
#include <AK/StdLibExtras.h>
|
#include <AK/StdLibExtras.h>
|
||||||
|
@ -124,7 +125,10 @@ public:
|
||||||
return size;
|
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
|
DisjointSpans slice(size_t start, size_t length) const
|
||||||
{
|
{
|
||||||
|
@ -256,7 +260,10 @@ public:
|
||||||
return sum;
|
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&
|
DisjointSpans<T> spans() const&
|
||||||
{
|
{
|
||||||
|
|
|
@ -13,8 +13,11 @@
|
||||||
TEST_CASE(basic)
|
TEST_CASE(basic)
|
||||||
{
|
{
|
||||||
DisjointChunks<size_t> chunks;
|
DisjointChunks<size_t> chunks;
|
||||||
|
EXPECT(chunks.is_empty());
|
||||||
chunks.append({});
|
chunks.append({});
|
||||||
|
EXPECT(chunks.is_empty());
|
||||||
chunks.last_chunk().append(0);
|
chunks.last_chunk().append(0);
|
||||||
|
EXPECT(!chunks.is_empty());
|
||||||
chunks.append({});
|
chunks.append({});
|
||||||
chunks.last_chunk().append(1);
|
chunks.last_chunk().append(1);
|
||||||
chunks.last_chunk().append(2);
|
chunks.last_chunk().append(2);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue