summaryrefslogtreecommitdiff
path: root/AK
diff options
context:
space:
mode:
authorAli Mohammad Pur <ali.mpfard@gmail.com>2022-11-16 01:22:34 +0330
committerAli Mohammad Pur <Ali.mpfard@gmail.com>2022-11-17 20:13:04 +0330
commitc2b20b5681bc6e5459c0a584ad42d9bec0016858 (patch)
tree52a06f338c432c34cae3f5fa0c706cca0e18ec40 /AK
parente9b9527440f008f653ac2a2b7bc04a6abcb2bd74 (diff)
downloadserenity-c2b20b5681bc6e5459c0a584ad42d9bec0016858.zip
AK: Give DisjointChunks::m_chunks an inline capacity of 1
That's one fewer level of indirection for flattened ones.
Diffstat (limited to 'AK')
-rw-r--r--AK/DisjointChunks.h17
1 files changed, 10 insertions, 7 deletions
diff --git a/AK/DisjointChunks.h b/AK/DisjointChunks.h
index 688604a02f..d07d3d8690 100644
--- a/AK/DisjointChunks.h
+++ b/AK/DisjointChunks.h
@@ -15,11 +15,11 @@
namespace AK {
-template<typename ChunkType, bool IsConst>
+template<typename ChunkType, bool IsConst, size_t InlineCapacity = 0>
struct DisjointIterator {
struct EndTag {
};
- using ReferenceType = Conditional<IsConst, AddConst<Vector<ChunkType>>, Vector<ChunkType>>&;
+ using ReferenceType = Conditional<IsConst, AddConst<Vector<ChunkType, InlineCapacity>>, Vector<ChunkType, InlineCapacity>>&;
DisjointIterator(ReferenceType chunks)
: m_chunks(chunks)
@@ -232,6 +232,9 @@ FixedArray<T> shatter_chunk(FixedArray<T>& source_chunk, size_t start, size_t sl
template<typename T, typename ChunkType = Vector<T>>
class DisjointChunks {
+private:
+ constexpr static auto InlineCapacity = IsCopyConstructible<ChunkType> ? 1 : 0;
+
public:
DisjointChunks() = default;
~DisjointChunks() = default;
@@ -397,10 +400,10 @@ public:
m_chunks.remove(1, m_chunks.size() - 1);
}
- DisjointIterator<ChunkType, false> begin() { return { m_chunks }; }
- DisjointIterator<ChunkType, false> end() { return { m_chunks, {} }; }
- DisjointIterator<ChunkType, true> begin() const { return { m_chunks }; }
- DisjointIterator<ChunkType, true> end() const { return { m_chunks, {} }; }
+ DisjointIterator<ChunkType, false, InlineCapacity> begin() { return { m_chunks }; }
+ DisjointIterator<ChunkType, false, InlineCapacity> end() { return { m_chunks, {} }; }
+ DisjointIterator<ChunkType, true, InlineCapacity> begin() const { return { m_chunks }; }
+ DisjointIterator<ChunkType, true, InlineCapacity> end() const { return { m_chunks, {} }; }
private:
struct ChunkAndOffset {
@@ -428,7 +431,7 @@ private:
return { &m_chunks.last(), index - (offset - m_chunks.last().size()) };
}
- Vector<ChunkType> m_chunks;
+ Vector<ChunkType, InlineCapacity> m_chunks;
};
}