libcamera/src
Khem Raj 299e8ef563 pipeline: uvcvideo: Avoid reference to temporary object
A range-based for loop whose range expression is an array of char
pointers and range variable declaration is a const reference to a
std::string creates a temporary string from the char pointer and binds
the range variable reference to it. This creates a const reference to a
temporary, which is valid in C++, and extends the lifetime of the
temporary to the lifetime of the reference.

However, lifetime extension in range-based for loops is considered as a
sign of a potential issue, as a temporary is created for every
iteration, which can be costly, and the usage of a reference in the
range declaration doesn't make it obvious that the code isn't simply
binding a reference to an existing object. gcc 11, with the
-Wrange-loop-construct option, flags this:

uvcvideo.cpp:432:33: error: loop variable 'name' of type 'const string&' {aka 'const std::__cxx11::basic_string<cha
r>&'} binds to a temporary constructed from type 'const char* const' [-Werror=range-loop-construct]
|   432 |         for (const std::string &name : { "idVendor", "idProduct" }) {
|       |                                 ^~~~

To please the compiler, make the range variable a const char *. This may
bring a tiny performance improvement, as the name is only used once, in
a location where the compiler can use

	operator+(const std::string &, const char *)

instead of

	operator+(const std::string &, const std::string &)

Signed-off-by: Khem Raj <raj.khem@gmail.com>
Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>

Use a const char * type instead of auto, and update the commit message
accordingly.

Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
2021-03-28 22:56:31 +03:00
..
android android: meson: Remove unneeded android_enabled check 2021-03-25 19:34:54 +02:00
cam meson: Summarize which applications and adaptation layers are built 2021-03-28 01:47:26 +02:00
gstreamer meson: Summarize which applications and adaptation layers are built 2021-03-28 01:47:26 +02:00
ipa ipa: raspberrrypi: Remove duplicate comment 2021-03-28 19:53:12 +03:00
libcamera pipeline: uvcvideo: Avoid reference to temporary object 2021-03-28 22:56:31 +03:00
qcam meson: Summarize which applications and adaptation layers are built 2021-03-28 01:47:26 +02:00
v4l2 meson: Summarize which applications and adaptation layers are built 2021-03-28 01:47:26 +02:00
meson.build cros: Support the new cros camera API with set_up and tear_down 2021-03-03 19:05:12 +09:00