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

Kieran Bingham kieran.bingham at ideasonboard.com
Mon May 20 12:09:59 CEST 2024


Quoting Barnabás Pőcze (2024-05-20 04:55:43)
> 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".

Can be fixed while applying to avoid the need for a v2.

Reviewed-by: Kieran Bingham <kieran.bingham at ideasonboard.com>

> > 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