See the update to ProgrammersManual.rst for the guidelines for
using these types. tl;dr: SVec for "small" vectors on the stack, Vec for
vectors on the heap / in data structures.
- SVec<T> is a convenience alias for SmallVector<T, N> with N
chosen automatically according to a heuristic described below.
- Vec<T> is a convenience alias for SmallVector<T, 0>.
These are expected to help systematically improve SmallVector use in the
LLVM codebase, which has historically been plagued by semi-arbitrary /
cargo culted N parameters, often leading to bad outcomes due to
excessive sizeof(SmallVector<T, N>). These aliases also make
programming more convenient by avoiding edit/rebuild cycles due to
forgetting to type the N parameter.
Notes on the SVec<T> default inline elements heuristic:
The initial policy is to guarantee a maximum upper bound of 64 bytes for
sizeof(SVec<T>).
This tends to match my intuition: depending on the element size, you
want to be careful about your small size -- basically we just want to
ensure not too much stack growth (or heap allocation growth for the
heap-allocated case). Also, looking back through llvm-dev, it looks like
Reid suggested something similar in
this thread.
This default also tends to avoid pathological situations if a programmer
does SVec<SVec<T>> (also mentioned in that thread as problematic). For
these, the sizeof the outer SVec will not amplify the sizeof the
inner SVec. Of course, users can do SVec<Vec<T>> to indicate that the
inner SmallVector's should have no inline elements. Then the outer SVec
automatically adapt, and fit some inner SmallVector's inline.
clang-tidy: warning: invalid case style for variable 'kDefaultSmallSizeHeaderSizeMultiplier' [readability-identifier-naming]
not useful