From patchwork Mon May 20 03:52:33 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Barnab=C3=A1s_P=C5=91cze?= X-Patchwork-Id: 20077 Return-Path: X-Original-To: parsemail@patchwork.libcamera.org Delivered-To: parsemail@patchwork.libcamera.org Received: from lancelot.ideasonboard.com (lancelot.ideasonboard.com [92.243.16.209]) by patchwork.libcamera.org (Postfix) with ESMTPS id B4F77BD78E for ; Mon, 20 May 2024 03:52:42 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id D4AFC6346B; Mon, 20 May 2024 05:52:41 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (2048-bit key; unprotected) header.d=protonmail.com header.i=@protonmail.com header.b="oXPs0z26"; dkim-atps=neutral Received: from mail-4322.protonmail.ch (mail-4322.protonmail.ch [185.70.43.22]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 4CDF861A4D for ; Mon, 20 May 2024 05:52:40 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=protonmail.com; s=protonmail3; t=1716177159; x=1716436359; bh=MShWpaRHXxxdimUORIqNYMuInBN6XYPtaDPuka5gWJY=; h=Date:To:From:Subject:Message-ID:Feedback-ID:From:To:Cc:Date: Subject:Reply-To:Feedback-ID:Message-ID:BIMI-Selector; b=oXPs0z2640hDytJdxRY9A0rW0SVTpIE62oSNl+XymvB3CHMGJpYkT7uI4Z6jzvpDK n9fda0nKIu1gknRUqlj1AC2O9rWBCCmpDEOdfBcxKma5aBa6i4fZt6eSf7j66Ag7II jjJeHjGAs0D4mN0JVp8K+Q1BijYlKXw81D+2auvxN7TUNynw5byE85+a+pTQEczIuX sswrxJJKmtOIJjI6ah5MFYfzjSi45XaevAjjt/gLNFs/1Tf6vXjtKYY4gncS8RF3q1 cPykwGMciLAiiFyXt571GXP3lvT8K2bFg2PGtMPNSfp91iWwYqT2DOQcUrOxUULzvA RLl2OkKgXNCmQ== Date: Mon, 20 May 2024 03:52:33 +0000 To: libcamera-devel@lists.libcamera.org From: =?utf-8?q?Barnab=C3=A1s_P=C5=91cze?= Subject: [PATCH v1] libcamera: yaml_parser: Avoid double lookup in `operator[]` Message-ID: <20240520035232.205777-1-pobrn@protonmail.com> Feedback-ID: 20568564:user:proton X-Pm-Message-ID: 097afb9f0ad7a09008cf6b17079ff986ec256172 MIME-Version: 1.0 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: , Errors-To: libcamera-devel-bounces@lists.libcamera.org Sender: "libcamera-devel" `YamlObject::contains()` does the same search, doing the lookup twice in unnecessary. Signed-off-by: Barnabás Pőcze Reviewed-by: Kieran Bingham Reviewed-by: Daniel Scally --- src/libcamera/yaml_parser.cpp | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/libcamera/yaml_parser.cpp b/src/libcamera/yaml_parser.cpp index 55f81916..aac9a2bd 100644 --- a/src/libcamera/yaml_parser.cpp +++ b/src/libcamera/yaml_parser.cpp @@ -468,10 +468,13 @@ bool YamlObject::contains(const std::string &key) const */ const YamlObject &YamlObject::operator[](const std::string &key) const { - if (type_ != Type::Dictionary || !contains(key)) + if (type_ != Type::Dictionary) return empty; auto iter = dictionary_.find(key); + if (iter == dictionary_.end()) + return empty; + return *iter->second; }