[PATCH v1] libcamera: yaml_parser: Avoid double lookup in `operator[]`
Dan Scally
dan.scally at ideasonboard.com
Tue May 21 09:10:42 CEST 2024
Hi Barnabas - thanks for the patch
On 20/05/2024 04:52, Barnabás Pőcze wrote:
> `YamlObject::contains()` does the same search,
> doing the lookup twice in unnecessary.
>
> Signed-off-by: Barnabás Pőcze <pobrn at protonmail.com>
Reviewed-by: Daniel Scally <dan.scally at ideasonboard.com>
> ---
> 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;
> }
>
More information about the libcamera-devel
mailing list