From 493f198e94f84e6453573f24f10a2a30edb3c9c0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Barnab=C3=A1s=20P=C5=91cze?= Date: Tue, 26 Nov 2024 18:03:10 +0000 Subject: treewide: Avoid some copies in range-based for loops MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Most of these have been found by the `performance-for-range-copy` check of `clang-tidy`. Signed-off-by: Barnabás Pőcze Reviewed-by: Laurent Pinchart Signed-off-by: Laurent Pinchart --- src/libcamera/camera_manager.cpp | 2 +- src/libcamera/converter.cpp | 5 +++-- src/libcamera/pipeline/virtual/image_frame_generator.cpp | 2 +- src/libcamera/pipeline_handler.cpp | 2 +- 4 files changed, 6 insertions(+), 5 deletions(-) (limited to 'src') diff --git a/src/libcamera/camera_manager.cpp b/src/libcamera/camera_manager.cpp index c7cc5adb..87e6717e 100644 --- a/src/libcamera/camera_manager.cpp +++ b/src/libcamera/camera_manager.cpp @@ -388,7 +388,7 @@ std::shared_ptr CameraManager::get(const std::string &id) MutexLocker locker(d->mutex_); - for (std::shared_ptr camera : d->cameras_) { + for (const std::shared_ptr &camera : d->cameras_) { if (camera->id() == id) return camera; } diff --git a/src/libcamera/converter.cpp b/src/libcamera/converter.cpp index 945f2527..3a3f8434 100644 --- a/src/libcamera/converter.cpp +++ b/src/libcamera/converter.cpp @@ -325,8 +325,9 @@ std::vector ConverterFactoryBase::names() for (ConverterFactoryBase *factory : factories) { list.push_back(factory->name_); - for (auto alias : factory->compatibles()) - list.push_back(alias); + + const auto &compatibles = factory->compatibles(); + list.insert(list.end(), compatibles.begin(), compatibles.end()); } return list; diff --git a/src/libcamera/pipeline/virtual/image_frame_generator.cpp b/src/libcamera/pipeline/virtual/image_frame_generator.cpp index 2baef588..277efbb0 100644 --- a/src/libcamera/pipeline/virtual/image_frame_generator.cpp +++ b/src/libcamera/pipeline/virtual/image_frame_generator.cpp @@ -39,7 +39,7 @@ ImageFrameGenerator::create(ImageFrames &imageFrames) * For each file in the directory, load the image, * convert it to NV12, and store the pointer. */ - for (std::filesystem::path path : imageFrames.files) { + for (const auto &path : imageFrames.files) { File file(path); if (!file.open(File::OpenModeFlag::ReadOnly)) { LOG(Virtual, Error) << "Failed to open image file " << file.fileName() diff --git a/src/libcamera/pipeline_handler.cpp b/src/libcamera/pipeline_handler.cpp index 991b06f2..caa5c20e 100644 --- a/src/libcamera/pipeline_handler.cpp +++ b/src/libcamera/pipeline_handler.cpp @@ -74,7 +74,7 @@ PipelineHandler::PipelineHandler(CameraManager *manager) PipelineHandler::~PipelineHandler() { - for (std::shared_ptr media : mediaDevices_) + for (std::shared_ptr &media : mediaDevices_) media->release(); } -- cgit v1.2.1