mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-11-25 00:50:22 +00:00
AK: Allow DisjointChunks::spans to return a vector with inline capacity
This commit is contained in:
parent
bee9412ae4
commit
f59bd33876
Notes:
sideshowbarker
2024-07-17 21:26:19 +09:00
Author: https://github.com/alimpfard Commit: https://github.com/SerenityOS/serenity/commit/f59bd33876 Pull-request: https://github.com/SerenityOS/serenity/pull/15994
1 changed files with 7 additions and 6 deletions
|
@ -70,7 +70,7 @@ private:
|
|||
ReferenceType m_chunks;
|
||||
};
|
||||
|
||||
template<typename T>
|
||||
template<typename T, typename SpanContainer = Vector<Span<T>>>
|
||||
class DisjointSpans {
|
||||
public:
|
||||
DisjointSpans() = default;
|
||||
|
@ -78,7 +78,7 @@ public:
|
|||
DisjointSpans(DisjointSpans const&) = default;
|
||||
DisjointSpans(DisjointSpans&&) = default;
|
||||
|
||||
explicit DisjointSpans(Vector<Span<T>> spans)
|
||||
explicit DisjointSpans(SpanContainer spans)
|
||||
: m_spans(move(spans))
|
||||
{
|
||||
}
|
||||
|
@ -185,7 +185,7 @@ private:
|
|||
return { m_spans.last(), index - (offset - m_spans.last().size()) };
|
||||
}
|
||||
|
||||
Vector<Span<T>> m_spans;
|
||||
SpanContainer m_spans;
|
||||
};
|
||||
|
||||
namespace Detail {
|
||||
|
@ -311,13 +311,14 @@ public:
|
|||
return all_of(m_chunks, [](auto& chunk) { return chunk.is_empty(); });
|
||||
}
|
||||
|
||||
DisjointSpans<T> spans() const&
|
||||
template<size_t InlineSize = 0>
|
||||
DisjointSpans<T, Vector<Span<T>, InlineSize>> spans() const&
|
||||
{
|
||||
Vector<Span<T>> spans;
|
||||
Vector<Span<T>, InlineSize> spans;
|
||||
spans.ensure_capacity(m_chunks.size());
|
||||
for (auto& chunk : m_chunks)
|
||||
spans.unchecked_append(const_cast<ChunkType&>(chunk).span());
|
||||
return DisjointSpans<T> { move(spans) };
|
||||
return DisjointSpans<T, Vector<Span<T>, InlineSize>> { move(spans) };
|
||||
}
|
||||
|
||||
bool operator==(DisjointChunks const& other) const
|
||||
|
|
Loading…
Reference in a new issue