[libcamera-devel] [PATCH] libcamera: Remove std::piecewise_construct where not necessary

Laurent Pinchart laurent.pinchart at ideasonboard.com
Tue Jan 14 21:14:52 CET 2020


When emplacing an element in a std::map, std::piecewise_construct is
required to forward the parameters to the constructors of the key and
mapped type, respectively. However, when the caller already has an
instance of the mapped type, forwarding it to the mapped type copy
constructor isn't really required, as the copy constructor would be
called anyway. Drop std::piecewise_construct in those cases. This does
not incur any performance cost.

Signed-off-by: Laurent Pinchart <laurent.pinchart at ideasonboard.com>
---
 src/libcamera/pipeline/uvcvideo.cpp | 4 +---
 src/libcamera/pipeline/vimc.cpp     | 4 +---
 2 files changed, 2 insertions(+), 6 deletions(-)

diff --git a/src/libcamera/pipeline/uvcvideo.cpp b/src/libcamera/pipeline/uvcvideo.cpp
index 83093676ec73..29afb121aa46 100644
--- a/src/libcamera/pipeline/uvcvideo.cpp
+++ b/src/libcamera/pipeline/uvcvideo.cpp
@@ -365,9 +365,7 @@ int UVCCameraData::init(MediaEntity *entity)
 			continue;
 		}
 
-		ctrls.emplace(std::piecewise_construct,
-			      std::forward_as_tuple(id),
-			      std::forward_as_tuple(range));
+		ctrls.emplace(id, range);
 	}
 
 	controlInfo_ = std::move(ctrls);
diff --git a/src/libcamera/pipeline/vimc.cpp b/src/libcamera/pipeline/vimc.cpp
index c99560a45cfa..b1054d307ea2 100644
--- a/src/libcamera/pipeline/vimc.cpp
+++ b/src/libcamera/pipeline/vimc.cpp
@@ -448,9 +448,7 @@ int VimcCameraData::init(MediaDevice *media)
 			continue;
 		}
 
-		ctrls.emplace(std::piecewise_construct,
-			      std::forward_as_tuple(id),
-			      std::forward_as_tuple(range));
+		ctrls.emplace(id, range);
 	}
 
 	controlInfo_ = std::move(ctrls);
-- 
Regards,

Laurent Pinchart



More information about the libcamera-devel mailing list