mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 04:37:34 +00:00
AK: Allow DisjointChunks::spans to return a vector with inline capacity
This commit is contained in:
parent
bee9412ae4
commit
f59bd33876
1 changed files with 7 additions and 6 deletions
|
@ -70,7 +70,7 @@ private:
|
||||||
ReferenceType m_chunks;
|
ReferenceType m_chunks;
|
||||||
};
|
};
|
||||||
|
|
||||||
template<typename T>
|
template<typename T, typename SpanContainer = Vector<Span<T>>>
|
||||||
class DisjointSpans {
|
class DisjointSpans {
|
||||||
public:
|
public:
|
||||||
DisjointSpans() = default;
|
DisjointSpans() = default;
|
||||||
|
@ -78,7 +78,7 @@ public:
|
||||||
DisjointSpans(DisjointSpans const&) = default;
|
DisjointSpans(DisjointSpans const&) = default;
|
||||||
DisjointSpans(DisjointSpans&&) = default;
|
DisjointSpans(DisjointSpans&&) = default;
|
||||||
|
|
||||||
explicit DisjointSpans(Vector<Span<T>> spans)
|
explicit DisjointSpans(SpanContainer spans)
|
||||||
: m_spans(move(spans))
|
: m_spans(move(spans))
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
@ -185,7 +185,7 @@ private:
|
||||||
return { m_spans.last(), index - (offset - m_spans.last().size()) };
|
return { m_spans.last(), index - (offset - m_spans.last().size()) };
|
||||||
}
|
}
|
||||||
|
|
||||||
Vector<Span<T>> m_spans;
|
SpanContainer m_spans;
|
||||||
};
|
};
|
||||||
|
|
||||||
namespace Detail {
|
namespace Detail {
|
||||||
|
@ -311,13 +311,14 @@ public:
|
||||||
return all_of(m_chunks, [](auto& chunk) { return chunk.is_empty(); });
|
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());
|
spans.ensure_capacity(m_chunks.size());
|
||||||
for (auto& chunk : m_chunks)
|
for (auto& chunk : m_chunks)
|
||||||
spans.unchecked_append(const_cast<ChunkType&>(chunk).span());
|
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
|
bool operator==(DisjointChunks const& other) const
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue