From patchwork Thu Dec 5 16:34:24 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: 22184 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 9B14DC323E for ; Thu, 5 Dec 2024 16:37:33 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 4CD946610A; Thu, 5 Dec 2024 17:37:33 +0100 (CET) Authentication-Results: lancelot.ideasonboard.com; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=protonmail.com header.i=@protonmail.com header.b="nCvEtIcB"; dkim-atps=neutral Received: from mail-40131.protonmail.ch (mail-40131.protonmail.ch [185.70.40.131]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id D50E06608C for ; Thu, 5 Dec 2024 17:37:31 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=protonmail.com; s=protonmail3; t=1733416641; x=1733675841; bh=t1h0h9GL4LKAg+YNzPdrr7QgYlXuCZ9t8j1zqNfJIuQ=; h=Date:To:From:Subject:Message-ID:In-Reply-To:References: Feedback-ID:From:To:Cc:Date:Subject:Reply-To:Feedback-ID: Message-ID:BIMI-Selector:List-Unsubscribe:List-Unsubscribe-Post; b=nCvEtIcBJDxsM0XDLgQeXaZwYcWsXQ8WqSC2ydyaIOY3xa6cttenVe488qcE78cPg HAlKxQ6DTBzyDbVxjk7FXxo+ZIgfQomu3nHc4rcyfpCXazWlziaV7UoDodTIK1Fdbv tIQwMeBna5XEzd0ExdwERtKN6YEiqdRuUGrwTITOq6q1gI2IbPGGzX4JTX0oY5vI81 /0G+IZ7nFc3C1omggHa/P4NjQAKVK0M2EB1xQvk1SoENV7Y3u4gQHtEqvz2cZbCEaS 9dGoxD29ttAcyko+IIvbUwMiQ3cdZU2l8TNkw/en/h2XTkjwwWWdg2Cvkgsx2AwcoO Q96MK1Es4s7vA== Date: Thu, 05 Dec 2024 16:34:24 +0000 To: libcamera-devel@lists.libcamera.org From: =?utf-8?q?Barnab=C3=A1s_P=C5=91cze?= Subject: [PATCH v1 3/3] libcamera: yaml_parser: Use `YamlObject::find()` in contains/operator[] Message-ID: <20241205163411.1160094-3-pobrn@protonmail.com> In-Reply-To: <20241205163411.1160094-1-pobrn@protonmail.com> References: <20241205163411.1160094-1-pobrn@protonmail.com> Feedback-ID: 20568564:user:proton X-Pm-Message-ID: b0c478d199faf3ed248621d9e6788bd138a266b3 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" Use `YamlObject::find()` to implement `YamlObject::{contains,operator[]}()`. This way there is a single source of truth for dictionary lookups. Furthermore, inline `YamlObject::contains()` as it can trivially be expressed as a call to `find()`. Signed-off-by: Barnabás Pőcze Reviewed-by: Laurent Pinchart --- include/libcamera/internal/yaml_parser.h | 6 +++++- src/libcamera/yaml_parser.cpp | 14 ++------------ 2 files changed, 7 insertions(+), 13 deletions(-) diff --git a/include/libcamera/internal/yaml_parser.h b/include/libcamera/internal/yaml_parser.h index 796e3e90..20dab2f3 100644 --- a/include/libcamera/internal/yaml_parser.h +++ b/include/libcamera/internal/yaml_parser.h @@ -207,7 +207,11 @@ public: const YamlObject &operator[](std::size_t index) const; - bool contains(std::string_view key) const; + bool contains(std::string_view key) const + { + return find(key); + } + const YamlObject &operator[](std::string_view key) const; const YamlObject *find(std::string_view key) const; diff --git a/src/libcamera/yaml_parser.cpp b/src/libcamera/yaml_parser.cpp index da8cb61f..72483ef3 100644 --- a/src/libcamera/yaml_parser.cpp +++ b/src/libcamera/yaml_parser.cpp @@ -369,10 +369,6 @@ const YamlObject &YamlObject::operator[](std::size_t index) const * * \return True if an element exists, false otherwise */ -bool YamlObject::contains(std::string_view key) const -{ - return dictionary_.find(key) != dictionary_.end(); -} /** * \fn YamlObject::operator[](std::string_view key) const @@ -387,14 +383,8 @@ bool YamlObject::contains(std::string_view key) const */ const YamlObject &YamlObject::operator[](std::string_view key) const { - if (type_ != Type::Dictionary) - return empty; - - auto iter = dictionary_.find(key); - if (iter == dictionary_.end()) - return empty; - - return *iter->second; + auto *child = find(key); + return child ? *child : empty; } /**