From patchwork Mon Mar 23 10:39:38 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Laurent Pinchart X-Patchwork-Id: 3242 X-Patchwork-Delegate: laurent.pinchart@ideasonboard.com Return-Path: Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [213.167.242.64]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 02D6160412 for ; Mon, 23 Mar 2020 11:39:51 +0100 (CET) Received: from pendragon.bb.dnainternet.fi (81-175-216-236.bb.dnainternet.fi [81.175.216.236]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id 748F3308 for ; Mon, 23 Mar 2020 11:39:51 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1584959991; bh=TYp/uvjUYfJj0y8WC83o79hIFy1y0tuZugUwaa0e64I=; h=From:To:Subject:Date:From; b=jYuYdq68p42tPjZQoRVtq0YqY2yKUgQliGxSzONhRxm/EL9lX2UXrk3tCzVOWLlMW ed+hLuKN9KktHKwWv7TnAcuShAcKaUYc1jT1NHewmMLWJC/maeMtfeCCcY2zFAgJMf 9a8KiyQ9P4TwwieNgdL/nDf6VBDwk2stRAO0tY6w= From: Laurent Pinchart To: libcamera-devel@lists.libcamera.org Date: Mon, 23 Mar 2020 12:39:38 +0200 Message-Id: <20200323103938.11026-1-laurent.pinchart@ideasonboard.com> X-Mailer: git-send-email 2.24.1 MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH] qcam: main: Cache lookup of role property X-BeenThere: libcamera-devel@lists.libcamera.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 23 Mar 2020 10:39:52 -0000 The code handling the stream role option retrieves the role property and converts it to a string in every branch. Cache it and use the cached value. Signed-off-by: Laurent Pinchart Reviewed-by: Kieran Bingham Reviewed-by: Niklas Söderlund --- src/cam/main.cpp | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/src/cam/main.cpp b/src/cam/main.cpp index 2a0a830ff371..56059ab6c047 100644 --- a/src/cam/main.cpp +++ b/src/cam/main.cpp @@ -209,17 +209,21 @@ int CamApp::prepareConfig() for (auto const &value : streamOptions) { KeyValueParser::Options opt = value.toKeyValues(); - if (!opt.isSet("role")) { - roles.push_back(StreamRole::VideoRecording); - } else if (opt["role"].toString() == "viewfinder") { + std::string role; + if (opt.isSet("role")) + role = opt["role"].toString(); + else + role = "viewfinder"; + + if (role == "viewfinder") { roles.push_back(StreamRole::Viewfinder); - } else if (opt["role"].toString() == "video") { + } else if (role == "video") { roles.push_back(StreamRole::VideoRecording); - } else if (opt["role"].toString() == "still") { + } else if (role == "still") { roles.push_back(StreamRole::StillCapture); } else { std::cerr << "Unknown stream role " - << opt["role"].toString() << std::endl; + << role << std::endl; return -EINVAL; } }