[PATCH v1] libcamera: yaml_parser: Avoid double lookup in `operator[]`

Barnabás Pőcze pobrn at protonmail.com
Mon May 20 05:55:43 CEST 2024


2024. május 20., hétfő 5:52 keltezéssel, Barnabás Pőcze <pobrn at protonmail.com> írta:

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

Oops, this should say "is" instead of "in".


> 
> Signed-off-by: Barnabás Pőcze <pobrn at protonmail.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;
>  }
>  
> -- 
> 2.45.1


More information about the libcamera-devel mailing list