From 168bb3c97c5f338486251ae7752bccd4e61ffcc0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Barnab=C3=A1s=20P=C5=91cze?= Date: Mon, 20 May 2024 03:52:33 +0000 Subject: libcamera: yaml_parser: Avoid double lookup in `operator[]` MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit `YamlObject::contains()` does the same search, doing the lookup twice is unnecessary. Signed-off-by: Barnabás Pőcze Reviewed-by: Kieran Bingham Reviewed-by: Daniel Scally Signed-off-by: Kieran Bingham --- 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; } -- cgit v1.2.1