summaryrefslogtreecommitdiff
path: root/src/py/examples
diff options
context:
space:
mode:
authorStefan Klug <stefan.klug@ideasonboard.com>2024-11-19 09:45:53 +0100
committerStefan Klug <stefan.klug@ideasonboard.com>2024-12-03 17:47:15 +0100
commit80f21e78a664cfae518a7b4e5d59cd8ff15b9e58 (patch)
tree6b4ce58ee1f3b87ea6f8ede69b34b284b0892472 /src/py/examples
parent056a0fe0ab7555055281f80923e12750f52ce080 (diff)
libcamera: internal: matrix: Replace vector with array in constructor
The Matrix constructor that takes a std::vector is meant and only used to initialize a Matrix from an initializer list. Using a std::vector is problematic for two reasons. First, it requires constructing a vector, copying the data from the initializer list, which is an expensive operation. Then, the vector size can't be verified at compile time, making the constructor unsafe. The first issue could be solved by replacing the vector with a std::initializer_list or a Span. The second issue would require checking the initializer list size with a static assertion, or restricting usage of the constructor to fixed-extent spans. Unfortunately, even if the size of initializer lists is always known at compile time, the std::initializer_list::size() function is a compile-time constant only for constant initializer lists. Using a span would work better, but construction of a fixed extent span from an initializer list must be explicit, making the API cumbersome. We can solve all those issues by passing an std::array to the constructor. Construction of an array from an initializer list can be implicit and doesn't involve a copy, and the array size is a template parameter and therefore guaranteed to be a compile-time constant. Signed-off-by: Stefan Klug <stefan.klug@ideasonboard.com> Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Diffstat (limited to 'src/py/examples')
0 files changed, 0 insertions, 0 deletions