jwmcglynn / donner

Donner SVG, a modern C++20 SVG rendering library supporting the latest SVG2 and CSS3 standards
https://jwmcglynn.github.io/donner/
ISC License
13 stars 1 forks source link

Create a SmallVector type #133

Closed jwmcglynn closed 5 months ago

jwmcglynn commented 7 months ago

This would be useful for AttributesComponent::findMatchingAttributes to return values without allocating in most scenarios

It would have a signature like:

SmallVector<T, DefaultSize> vec;

Beyond the DefaultSize allocations will still be allowed but the vector will move to the heap. Ideally this would use a small-string-style optimization.

Example storage

struct ShortData {
   std::array<T, DefaultSize> data;
};

struct LongData {
  std::vector<T> data;
};

Storage storage; // union/variant of ShortData/LongData
T* data; // To make data access non-branching?
size_t size; // To make .size() calls non-branching