{"id":27560,"url":"https://patchwork.libcamera.org/api/patches/27560/?format=json","web_url":"https://patchwork.libcamera.org/patch/27560/","project":{"id":1,"url":"https://patchwork.libcamera.org/api/projects/1/?format=json","name":"libcamera","link_name":"libcamera","list_id":"libcamera_core","list_email":"libcamera-devel@lists.libcamera.org","web_url":"","scm_url":"","webscm_url":""},"msgid":"<20260803131435.153927-12-barnabas.pocze@ideasonboard.com>","date":"2026-08-03T13:13:56","name":"[RFC,v3,11/50] ipa: libipa: agc_mean_luminance: Avoid some duplicate lookups","commit_ref":null,"pull_url":null,"state":"new","archived":false,"hash":"951228b5772331d18d82f7c7aa5e223522a2ade1","submitter":{"id":216,"url":"https://patchwork.libcamera.org/api/people/216/?format=json","name":"Barnabás Pőcze","email":"barnabas.pocze@ideasonboard.com"},"delegate":null,"mbox":"https://patchwork.libcamera.org/patch/27560/mbox/","series":[{"id":6103,"url":"https://patchwork.libcamera.org/api/series/6103/?format=json","web_url":"https://patchwork.libcamera.org/project/libcamera/list/?series=6103","date":"2026-08-03T13:13:45","name":"ipa: libipa: agc rework","version":3,"mbox":"https://patchwork.libcamera.org/series/6103/mbox/"}],"comments":"https://patchwork.libcamera.org/api/patches/27560/comments/","check":"pending","checks":"https://patchwork.libcamera.org/api/patches/27560/checks/","tags":{},"headers":{"Return-Path":"<libcamera-devel-bounces@lists.libcamera.org>","X-Original-To":"parsemail@patchwork.libcamera.org","Delivered-To":"parsemail@patchwork.libcamera.org","Received":["from lancelot.ideasonboard.com (lancelot.ideasonboard.com\n\t[92.243.16.209])\n\tby patchwork.libcamera.org (Postfix) with ESMTPS id C5E6CC32FE\n\tfor <parsemail@patchwork.libcamera.org>;\n\tMon,  3 Aug 2026 13:15:04 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 4E68C680CD;\n\tMon,  3 Aug 2026 15:14:51 +0200 (CEST)","from perceval.ideasonboard.com (perceval.ideasonboard.com\n\t[213.167.242.64])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 8DCFE68079\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tMon,  3 Aug 2026 15:14:41 +0200 (CEST)","from pb-laptop.local (185.221.141.208.nat.pool.zt.hu\n\t[185.221.141.208])\n\tby perceval.ideasonboard.com (Postfix) with ESMTPSA id A3555D77;\n\tMon,  3 Aug 2026 15:13:32 +0200 (CEST)"],"Authentication-Results":"lancelot.ideasonboard.com; dkim=pass (1024-bit key;\n\tunprotected) header.d=ideasonboard.com header.i=@ideasonboard.com\n\theader.b=\"fsGSiHZk\"; dkim-atps=neutral","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1785762812;\n\tbh=TF3uAZiCUgk7wKcS0YTwytYDzyJKf7Ep6UusEIImEIw=;\n\th=From:To:Cc:Subject:Date:In-Reply-To:References:From;\n\tb=fsGSiHZkorcL2LFSRVW4oaJzOYrr0PTSyTy5tJtWf6LxiUA1iXa9qnNg5BEblh/4P\n\tvnJQLVaMNXOhHxQR2goc2ZNAR4iPdOE24WpSZVHassAeebdMe1y8xBi+sdMhP1Gp6N\n\ti+zmKN+Z+wJKBPbjnpzjQhTVxHgTBEAAoESuJNX0=","From":"=?utf-8?q?Barnab=C3=A1s_P=C5=91cze?= <barnabas.pocze@ideasonboard.com>","To":"libcamera-devel@lists.libcamera.org","Cc":"Jacopo Mondi <jacopo.mondi@ideasonboard.com>","Subject":"[RFC PATCH v3 11/50] ipa: libipa: agc_mean_luminance: Avoid some\n\tduplicate lookups","Date":"Mon,  3 Aug 2026 15:13:56 +0200","Message-ID":"<20260803131435.153927-12-barnabas.pocze@ideasonboard.com>","X-Mailer":"git-send-email 2.55.0","In-Reply-To":"<20260803131435.153927-1-barnabas.pocze@ideasonboard.com>","References":"<20260803131435.153927-1-barnabas.pocze@ideasonboard.com>","MIME-Version":"1.0","Content-Type":"text/plain; charset=UTF-8","Content-Transfer-Encoding":"8bit","X-BeenThere":"libcamera-devel@lists.libcamera.org","X-Mailman-Version":"2.1.29","Precedence":"list","List-Id":"<libcamera-devel.lists.libcamera.org>","List-Unsubscribe":"<https://lists.libcamera.org/options/libcamera-devel>,\n\t<mailto:libcamera-devel-request@lists.libcamera.org?subject=unsubscribe>","List-Archive":"<https://lists.libcamera.org/pipermail/libcamera-devel/>","List-Post":"<mailto:libcamera-devel@lists.libcamera.org>","List-Help":"<mailto:libcamera-devel-request@lists.libcamera.org?subject=help>","List-Subscribe":"<https://lists.libcamera.org/listinfo/libcamera-devel>,\n\t<mailto:libcamera-devel-request@lists.libcamera.org?subject=subscribe>","Errors-To":"libcamera-devel-bounces@lists.libcamera.org","Sender":"\"libcamera-devel\" <libcamera-devel-bounces@lists.libcamera.org>"},"content":"Use iterators/references to avoid multiple map lookups. Also adjust\nthe no exposure mode / constraint cases to look similar.\n\nSigned-off-by: Barnabás Pőcze <barnabas.pocze@ideasonboard.com>\nReviewed-by: Jacopo Mondi <jacopo.mondi@ideasonboard.com>\n---\n src/ipa/libipa/agc_mean_luminance.cpp | 35 +++++++++++----------------\n 1 file changed, 14 insertions(+), 21 deletions(-)","diff":"diff --git a/src/ipa/libipa/agc_mean_luminance.cpp b/src/ipa/libipa/agc_mean_luminance.cpp\nindex 2879d3f58e..1b0c43febf 100644\n--- a/src/ipa/libipa/agc_mean_luminance.cpp\n+++ b/src/ipa/libipa/agc_mean_luminance.cpp\n@@ -224,14 +224,12 @@ int AgcMeanLuminance::parseConstraint(const ValueNode &modeDict, int32_t id)\n \t\t}\n \n \t\tAgcConstraint constraint = { bound, qLo, qHi, std::move(*yTarget) };\n-\n-\t\tif (!constraintModes_.count(id))\n-\t\t\tconstraintModes_[id] = {};\n+\t\tauto &constraints = constraintModes_[id];\n \n \t\tif (idx)\n-\t\t\tconstraintModes_[id].push_back(constraint);\n+\t\t\tconstraints.push_back(std::move(constraint));\n \t\telse\n-\t\t\tconstraintModes_[id].insert(constraintModes_[id].begin(), constraint);\n+\t\t\tconstraints.insert(constraints.begin(), std::move(constraint));\n \t}\n \n \treturn 0;\n@@ -244,8 +242,8 @@ int AgcMeanLuminance::parseConstraintModes(const ValueNode &tuningData)\n \tconst ValueNode &constraintModes = tuningData[controls::AeConstraintMode.name()];\n \tif (constraintModes.isDictionary()) {\n \t\tfor (const auto &[modeName, modeDict] : constraintModes.asDict()) {\n-\t\t\tif (AeConstraintModeNameValueMap.find(modeName) ==\n-\t\t\t    AeConstraintModeNameValueMap.end()) {\n+\t\t\tauto it = AeConstraintModeNameValueMap.find(modeName);\n+\t\t\tif (it == AeConstraintModeNameValueMap.end()) {\n \t\t\t\tLOG(AgcMeanLuminance, Warning)\n \t\t\t\t\t<< \"Skipping unknown constraint mode '\" << modeName << \"'\";\n \t\t\t\tcontinue;\n@@ -257,13 +255,11 @@ int AgcMeanLuminance::parseConstraintModes(const ValueNode &tuningData)\n \t\t\t\treturn -EINVAL;\n \t\t\t}\n \n-\t\t\tint ret = parseConstraint(modeDict,\n-\t\t\t\t\t\t  AeConstraintModeNameValueMap.at(modeName));\n+\t\t\tint ret = parseConstraint(modeDict, it->second);\n \t\t\tif (ret)\n \t\t\t\treturn ret;\n \n-\t\t\tavailableConstraintModes.push_back(\n-\t\t\t\tAeConstraintModeNameValueMap.at(modeName));\n+\t\t\tavailableConstraintModes.push_back(it->second);\n \t\t}\n \t}\n \n@@ -281,9 +277,7 @@ int AgcMeanLuminance::parseConstraintModes(const ValueNode &tuningData)\n \t\t\tPwl({ { { 0.0, 0.5 } } })\n \t\t};\n \n-\t\tconstraintModes_[controls::ConstraintNormal].insert(\n-\t\t\tconstraintModes_[controls::ConstraintNormal].begin(),\n-\t\t\tconstraint);\n+\t\tconstraintModes_[controls::ConstraintNormal].push_back(std::move(constraint));\n \t\tavailableConstraintModes.push_back(controls::ConstraintNormal);\n \t}\n \n@@ -299,8 +293,8 @@ int AgcMeanLuminance::parseExposureModes(const ValueNode &tuningData)\n \tconst ValueNode &exposureModes = tuningData[controls::AeExposureMode.name()];\n \tif (exposureModes.isDictionary()) {\n \t\tfor (const auto &[modeName, modeValues] : exposureModes.asDict()) {\n-\t\t\tif (AeExposureModeNameValueMap.find(modeName) ==\n-\t\t\t    AeExposureModeNameValueMap.end()) {\n+\t\t\tauto it = AeExposureModeNameValueMap.find(modeName);\n+\t\t\tif (it == AeExposureModeNameValueMap.end()) {\n \t\t\t\tLOG(AgcMeanLuminance, Warning)\n \t\t\t\t\t<< \"Skipping unknown exposure mode '\" << modeName << \"'\";\n \t\t\t\tcontinue;\n@@ -340,8 +334,8 @@ int AgcMeanLuminance::parseExposureModes(const ValueNode &tuningData)\n \t\t\tstd::shared_ptr<ExposureModeHelper> helper =\n \t\t\t\tstd::make_shared<ExposureModeHelper>(stages);\n \n-\t\t\texposureModeHelpers_[AeExposureModeNameValueMap.at(modeName)] = helper;\n-\t\t\tavailableExposureModes.push_back(AeExposureModeNameValueMap.at(modeName));\n+\t\t\texposureModeHelpers_.try_emplace(it->second, std::move(helper));\n+\t\t\tavailableExposureModes.push_back(it->second);\n \t\t}\n \t}\n \n@@ -352,14 +346,13 @@ int AgcMeanLuminance::parseExposureModes(const ValueNode &tuningData)\n \t * possible before touching gain.\n \t */\n \tif (availableExposureModes.empty()) {\n-\t\tint32_t exposureModeId = controls::ExposureNormal;\n \t\tstd::vector<std::pair<utils::Duration, double>> stages = { };\n \n \t\tstd::shared_ptr<ExposureModeHelper> helper =\n \t\t\tstd::make_shared<ExposureModeHelper>(stages);\n \n-\t\texposureModeHelpers_[exposureModeId] = helper;\n-\t\tavailableExposureModes.push_back(exposureModeId);\n+\t\texposureModeHelpers_.try_emplace(controls::ExposureNormal, std::move(helper));\n+\t\tavailableExposureModes.push_back(controls::ExposureNormal);\n \t}\n \n \tcontrols_[&controls::AeExposureMode] = ControlInfo(availableExposureModes);\n","prefixes":["RFC","v3","11/50"]}