libcamera: yaml_parser: Avoid double lookup in operator[]

`YamlObject::contains()` does the same search, doing the lookup twice is
unnecessary.

Signed-off-by: Barnabás Pőcze <pobrn@protonmail.com>
Reviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
Reviewed-by: Daniel Scally <dan.scally@ideasonboard.com>
Signed-off-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
This commit is contained in:
Barnabás Pőcze 2024-05-20 03:52:33 +00:00 committed by Kieran Bingham
parent e77a275110
commit 168bb3c97c

View file

@ -468,10 +468,13 @@ bool YamlObject::contains(const std::string &key) const
*/ */
const YamlObject &YamlObject::operator[](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; return empty;
auto iter = dictionary_.find(key); auto iter = dictionary_.find(key);
if (iter == dictionary_.end())
return empty;
return *iter->second; return *iter->second;
} }