AK: Allow DisjointChunks::spans to return a vector with inline capacity

This commit is contained in:
Ali Mohammad Pur 2022-11-03 10:29:34 +03:30 committed by Ali Mohammad Pur
parent bee9412ae4
commit f59bd33876
Notes: sideshowbarker 2024-07-17 21:26:19 +09:00

View file

@ -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