Commit graph

2 commits

Author SHA1 Message Date
Karl Wiberg
d084ea93b6 BoundedInlineVector: Add resize() method
Bug: webrtc:11391
Change-Id: I34d659d0e295617e9058393d4d1b510111a78b83
Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/169520
Commit-Queue: Karl Wiberg <kwiberg@webrtc.org>
Reviewed-by: Danil Chapovalov <danilchap@webrtc.org>
Reviewed-by: Mirko Bonadei <mbonadei@webrtc.org>
Cr-Commit-Position: refs/heads/master@{#30664}
2020-03-02 20:55:28 +00:00
Karl Wiberg
c126937564 BoundedInlineVector: Vector class of bounded size with inline allocation
Selling point is that it never touches the heap. Intended use case is
cheaply returning a variable, bounded, and small number of things from
a function.

Specifically, there are situations where we'd like to return things like

  ArrayView<ArrayView<float>>

where we currently have to allocate an array of ArrayView<float> for
the outer ArrayView to point to, which is a bother; however, although
the outer ArrayView is of variable size, that size is statically
guaranteed to not exceed some small constant. After this CL, we'll be
able to instead return

  BoundedInlineVector<ArrayView<float>, kSmallConstant>

which is much more convenient. We already had the option of returning e.g.

  std::vector<ArrayView<float>>

but that would bloat our binary with code to handle heap allocations
in places we'd rather be lean and mean.

https://godbolt.org/z/r-vcPj demonstrates that the overhead compared to
a raw C array + a size is ~zero.

Bug: webrtc:11391
Change-Id: Ifb6d937193052588be641aa62cc67ba0ec64ded6
Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/168944
Commit-Queue: Karl Wiberg <kwiberg@webrtc.org>
Reviewed-by: Mirko Bonadei <mbonadei@webrtc.org>
Reviewed-by: Per Åhgren <peah@webrtc.org>
Reviewed-by: Danil Chapovalov <danilchap@webrtc.org>
Cr-Commit-Position: refs/heads/master@{#30663}
2020-03-02 20:45:58 +00:00