[{"id":31533,"web_url":"https://patchwork.libcamera.org/comment/31533/","msgid":"<172790598287.2371408.10570747008840571860@ping.linuxembedded.co.uk>","date":"2024-10-02T21:53:02","subject":"Re: [PATCH v1] libcamera: yaml_parser: Take string keys in\n\t`std::string_view`","submitter":{"id":4,"url":"https://patchwork.libcamera.org/api/people/4/","name":"Kieran Bingham","email":"kieran.bingham@ideasonboard.com"},"content":"Quoting Barnabás Pőcze (2024-10-01 17:03:32)\n> In many cases a static string literal is used as key. Thus\n> having the argument type be `const std::string&` is suboptimal\n> since an `std::string` object needs to be constructed before\n> the call.\n> \n> C++17 introduced `std::string_view`, using which the call\n> can be done with less overhead, as the `std::string_view`\n> is non-owning and may be passed in registers entirely.\n> \n> So make `YamlObject::{contains,operator[]}` take the string keys\n> in `std::string_view`s.\n> \n> Unfortunately, that is not sufficient yet, because `std::map::find()`\n> takes an reference to `const key_type`, which would be `const std::string&`\n> in the case of `YamlParser`. However, with a transparent comparator\n> such as `std::less<>` `std::map::find()` is able to accept any\n> object as the argument, and it forwards it to the comparator.\n> \n> So make `YamlParser::dictionary_` use `std::less<>` as the comparator\n> to enable the use of `std::map::find()` with any type of argument.\n> \n> Signed-off-by: Barnabás Pőcze <pobrn@protonmail.com>\n\nThis passes the CI and unit tests at\nhttps://gitlab.freedesktop.org/camera/libcamera/-/pipelines/1281981\nwhich includes tests covering the yaml-parser.\n\nI don't think I would have spotted this ... but it looks and sounds\nreasonable to me ...\n\nMakes me wonder if sometimes we should just use a raw 'const char *'\n(</me ducks>) ;-) but I think this gives us that with type/length safety\non top so seems like a win to me.\n\nReviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com>\n\n> ---\n>  include/libcamera/internal/yaml_parser.h |  7 ++++---\n>  src/libcamera/yaml_parser.cpp            | 11 ++++-------\n>  2 files changed, 8 insertions(+), 10 deletions(-)\n> \n> diff --git a/include/libcamera/internal/yaml_parser.h b/include/libcamera/internal/yaml_parser.h\n> index 6211ff4a..de452844 100644\n> --- a/include/libcamera/internal/yaml_parser.h\n> +++ b/include/libcamera/internal/yaml_parser.h\n> @@ -12,6 +12,7 @@\n>  #include <optional>\n>  #include <stdint.h>\n>  #include <string>\n> +#include <string_view>\n>  #include <vector>\n>  \n>  #include <libcamera/base/class.h>\n> @@ -206,8 +207,8 @@ public:\n>  \n>         const YamlObject &operator[](std::size_t index) const;\n>  \n> -       bool contains(const std::string &key) const;\n> -       const YamlObject &operator[](const std::string &key) const;\n> +       bool contains(std::string_view key) const;\n> +       const YamlObject &operator[](std::string_view key) const;\n>  \n>  private:\n>         LIBCAMERA_DISABLE_COPY_AND_MOVE(YamlObject)\n> @@ -232,7 +233,7 @@ private:\n>  \n>         std::string value_;\n>         Container list_;\n> -       std::map<std::string, YamlObject *> dictionary_;\n> +       std::map<std::string, YamlObject *, std::less<>> dictionary_;\n>  };\n>  \n>  class YamlParser final\n> diff --git a/src/libcamera/yaml_parser.cpp b/src/libcamera/yaml_parser.cpp\n> index 4784f2dc..7c0b341a 100644\n> --- a/src/libcamera/yaml_parser.cpp\n> +++ b/src/libcamera/yaml_parser.cpp\n> @@ -481,16 +481,13 @@ const YamlObject &YamlObject::operator[](std::size_t index) const\n>   *\n>   * \\return True if an element exists, false otherwise\n>   */\n> -bool YamlObject::contains(const std::string &key) const\n> +bool YamlObject::contains(std::string_view key) const\n>  {\n> -       if (dictionary_.find(std::ref(key)) == dictionary_.end())\n> -               return false;\n> -\n> -       return true;\n> +       return dictionary_.find(key) != dictionary_.end();\n>  }\n>  \n>  /**\n> - * \\fn YamlObject::operator[](const std::string &key) const\n> + * \\fn YamlObject::operator[](std::string_view key) const\n>   * \\brief Retrieve a member by name from the dictionary\n>   *\n>   * This function retrieve a member of a YamlObject by name. Only YamlObject\n> @@ -500,7 +497,7 @@ bool YamlObject::contains(const std::string &key) const\n>   *\n>   * \\return The YamlObject corresponding to the \\a key member\n>   */\n> -const YamlObject &YamlObject::operator[](const std::string &key) const\n> +const YamlObject &YamlObject::operator[](std::string_view key) const\n>  {\n>         if (type_ != Type::Dictionary)\n>                 return empty;\n> -- \n> 2.46.2\n> \n>","headers":{"Return-Path":"<libcamera-devel-bounces@lists.libcamera.org>","X-Original-To":"parsemail@patchwork.libcamera.org","Delivered-To":"parsemail@patchwork.libcamera.org","Received":["from lancelot.ideasonboard.com (lancelot.ideasonboard.com\n\t[92.243.16.209])\n\tby patchwork.libcamera.org (Postfix) with ESMTPS id 08378BD80A\n\tfor <parsemail@patchwork.libcamera.org>;\n\tWed,  2 Oct 2024 21:53:09 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 1070E63525;\n\tWed,  2 Oct 2024 23:53:08 +0200 (CEST)","from perceval.ideasonboard.com (perceval.ideasonboard.com\n\t[213.167.242.64])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id B33DA63510\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tWed,  2 Oct 2024 23:53:06 +0200 (CEST)","from pendragon.ideasonboard.com\n\t(cpc89244-aztw30-2-0-cust6594.18-1.cable.virginm.net [86.31.185.195])\n\tby perceval.ideasonboard.com (Postfix) with ESMTPSA id E9B75581;\n\tWed,  2 Oct 2024 23:51:33 +0200 (CEST)"],"Authentication-Results":"lancelot.ideasonboard.com; dkim=pass (1024-bit key;\n\tunprotected) header.d=ideasonboard.com header.i=@ideasonboard.com\n\theader.b=\"gGo1Mlsz\"; dkim-atps=neutral","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1727905894;\n\tbh=BVORwqbMy6DvkNy4xMsP55daryQpIOjubCJto5RjT1Q=;\n\th=In-Reply-To:References:Subject:From:To:Date:From;\n\tb=gGo1MlszIqNYcOQefeCULwGtyPldUc9WgOgHrL9o5Ns8gApJZ6pesoQZ6Q2jFy7Gb\n\tZjDoKeRPHJT4gVf6XuRKOVvjC++P8cAeicWPme5HLwFtsPk2q+It+n002z6zIwn40K\n\tpMMjHVVcyPGxdD4TtSh+7r4FD1i4QExoZSLo/vJw=","Content-Type":"text/plain; charset=\"utf-8\"","MIME-Version":"1.0","Content-Transfer-Encoding":"quoted-printable","In-Reply-To":"<20241001160329.725278-1-pobrn@protonmail.com>","References":"<20241001160329.725278-1-pobrn@protonmail.com>","Subject":"Re: [PATCH v1] libcamera: yaml_parser: Take string keys in\n\t`std::string_view`","From":"Kieran Bingham <kieran.bingham@ideasonboard.com>","To":"=?utf-8?q?Barnab=C3=A1s_P=C5=91cze?= <pobrn@protonmail.com>,\n\tlibcamera-devel@lists.libcamera.org","Date":"Wed, 02 Oct 2024 22:53:02 +0100","Message-ID":"<172790598287.2371408.10570747008840571860@ping.linuxembedded.co.uk>","User-Agent":"alot/0.10","X-BeenThere":"libcamera-devel@lists.libcamera.org","X-Mailman-Version":"2.1.29","Precedence":"list","List-Id":"<libcamera-devel.lists.libcamera.org>","List-Unsubscribe":"<https://lists.libcamera.org/options/libcamera-devel>,\n\t<mailto:libcamera-devel-request@lists.libcamera.org?subject=unsubscribe>","List-Archive":"<https://lists.libcamera.org/pipermail/libcamera-devel/>","List-Post":"<mailto:libcamera-devel@lists.libcamera.org>","List-Help":"<mailto:libcamera-devel-request@lists.libcamera.org?subject=help>","List-Subscribe":"<https://lists.libcamera.org/listinfo/libcamera-devel>,\n\t<mailto:libcamera-devel-request@lists.libcamera.org?subject=subscribe>","Errors-To":"libcamera-devel-bounces@lists.libcamera.org","Sender":"\"libcamera-devel\" <libcamera-devel-bounces@lists.libcamera.org>"}},{"id":31535,"web_url":"https://patchwork.libcamera.org/comment/31535/","msgid":"<xNcBb6FHnd3KDtJhZYgY10d1DCJUCd0-WpgkAQyiiUvEZGv7A71EmkiBOYig80BWnUHDGBCVEzYKvr-iNI3qP1nj4KnBz2p6J5vvKfR2wG4=@protonmail.com>","date":"2024-10-02T22:26:14","subject":"Re: [PATCH v1] libcamera: yaml_parser: Take string keys in\n\t`std::string_view`","submitter":{"id":133,"url":"https://patchwork.libcamera.org/api/people/133/","name":"Pőcze Barnabás","email":"pobrn@protonmail.com"},"content":"> Quoting Barnabás Pőcze (2024-10-01 17:03:32)\n> > In many cases a static string literal is used as key. Thus\n> > having the argument type be `const std::string&` is suboptimal\n> > since an `std::string` object needs to be constructed before\n> > the call.\n> >\n> > C++17 introduced `std::string_view`, using which the call\n> > can be done with less overhead, as the `std::string_view`\n> > is non-owning and may be passed in registers entirely.\n> >\n> > So make `YamlObject::{contains,operator[]}` take the string keys\n> > in `std::string_view`s.\n> >\n> > Unfortunately, that is not sufficient yet, because `std::map::find()`\n> > takes an reference to `const key_type`, which would be `const std::string&`\n> > in the case of `YamlParser`. However, with a transparent comparator\n> > such as `std::less<>` `std::map::find()` is able to accept any\n> > object as the argument, and it forwards it to the comparator.\n> >\n> > So make `YamlParser::dictionary_` use `std::less<>` as the comparator\n> > to enable the use of `std::map::find()` with any type of argument.\n> >\n> > Signed-off-by: Barnabás Pőcze <pobrn@protonmail.com>\n> \n> This passes the CI and unit tests at\n> https://gitlab.freedesktop.org/camera/libcamera/-/pipelines/1281981\n> which includes tests covering the yaml-parser.\n> \n> I don't think I would have spotted this ... but it looks and sounds\n> reasonable to me ...\n> \n> Makes me wonder if sometimes we should just use a raw 'const char *'\n> (</me ducks>) ;-) but I think this gives us that with type/length safety\n> on top so seems like a win to me.\n\nI think `const std::string&` is generally not the ideal choice for the type of a\nfunction argument. I believe `std::string_view` is preferable, even `const char *`,\nwhen NUL termination is needed because one wants to interface with such APIs.\nIf both work, then `std::string_view` has the advantage of being more flexible\nwhile avoiding the need to call `strlen()` left and right.\n\n\nRegards,\nBarnabás Pőcze\n\n\n> \n> Reviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com>\n> \n> > ---\n> >  include/libcamera/internal/yaml_parser.h |  7 ++++---\n> >  src/libcamera/yaml_parser.cpp            | 11 ++++-------\n> >  2 files changed, 8 insertions(+), 10 deletions(-)\n> >\n> > diff --git a/include/libcamera/internal/yaml_parser.h b/include/libcamera/internal/yaml_parser.h\n> > index 6211ff4a..de452844 100644\n> > --- a/include/libcamera/internal/yaml_parser.h\n> > +++ b/include/libcamera/internal/yaml_parser.h\n> > @@ -12,6 +12,7 @@\n> >  #include <optional>\n> >  #include <stdint.h>\n> >  #include <string>\n> > +#include <string_view>\n> >  #include <vector>\n> >\n> >  #include <libcamera/base/class.h>\n> > @@ -206,8 +207,8 @@ public:\n> >\n> >         const YamlObject &operator[](std::size_t index) const;\n> >\n> > -       bool contains(const std::string &key) const;\n> > -       const YamlObject &operator[](const std::string &key) const;\n> > +       bool contains(std::string_view key) const;\n> > +       const YamlObject &operator[](std::string_view key) const;\n> >\n> >  private:\n> >         LIBCAMERA_DISABLE_COPY_AND_MOVE(YamlObject)\n> > @@ -232,7 +233,7 @@ private:\n> >\n> >         std::string value_;\n> >         Container list_;\n> > -       std::map<std::string, YamlObject *> dictionary_;\n> > +       std::map<std::string, YamlObject *, std::less<>> dictionary_;\n> >  };\n> >\n> >  class YamlParser final\n> > diff --git a/src/libcamera/yaml_parser.cpp b/src/libcamera/yaml_parser.cpp\n> > index 4784f2dc..7c0b341a 100644\n> > --- a/src/libcamera/yaml_parser.cpp\n> > +++ b/src/libcamera/yaml_parser.cpp\n> > @@ -481,16 +481,13 @@ const YamlObject &YamlObject::operator[](std::size_t index) const\n> >   *\n> >   * \\return True if an element exists, false otherwise\n> >   */\n> > -bool YamlObject::contains(const std::string &key) const\n> > +bool YamlObject::contains(std::string_view key) const\n> >  {\n> > -       if (dictionary_.find(std::ref(key)) == dictionary_.end())\n> > -               return false;\n> > -\n> > -       return true;\n> > +       return dictionary_.find(key) != dictionary_.end();\n> >  }\n> >\n> >  /**\n> > - * \\fn YamlObject::operator[](const std::string &key) const\n> > + * \\fn YamlObject::operator[](std::string_view key) const\n> >   * \\brief Retrieve a member by name from the dictionary\n> >   *\n> >   * This function retrieve a member of a YamlObject by name. Only YamlObject\n> > @@ -500,7 +497,7 @@ bool YamlObject::contains(const std::string &key) const\n> >   *\n> >   * \\return The YamlObject corresponding to the \\a key member\n> >   */\n> > -const YamlObject &YamlObject::operator[](const std::string &key) const\n> > +const YamlObject &YamlObject::operator[](std::string_view key) const\n> >  {\n> >         if (type_ != Type::Dictionary)\n> >                 return empty;\n> > --\n> > 2.46.2\n> >\n> >\n>","headers":{"Return-Path":"<libcamera-devel-bounces@lists.libcamera.org>","X-Original-To":"parsemail@patchwork.libcamera.org","Delivered-To":"parsemail@patchwork.libcamera.org","Received":["from lancelot.ideasonboard.com (lancelot.ideasonboard.com\n\t[92.243.16.209])\n\tby patchwork.libcamera.org (Postfix) with ESMTPS id 6678CBD80A\n\tfor <parsemail@patchwork.libcamera.org>;\n\tWed,  2 Oct 2024 22:26:23 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id F23D063525;\n\tThu,  3 Oct 2024 00:26:21 +0200 (CEST)","from mail-4316.protonmail.ch (mail-4316.protonmail.ch\n\t[185.70.43.16])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id CD53F60553\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tThu,  3 Oct 2024 00:26:19 +0200 (CEST)"],"Authentication-Results":"lancelot.ideasonboard.com; dkim=pass (2048-bit key;\n\tunprotected) header.d=protonmail.com header.i=@protonmail.com\n\theader.b=\"N84QNaEB\"; dkim-atps=neutral","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/relaxed; d=protonmail.com;\n\ts=protonmail3; t=1727907978; x=1728167178;\n\tbh=2EjDau9aE3+j1tFy5ucyuc2LbPXlNpEd3keco4pdntk=;\n\th=Date:To:From:Cc:Subject:Message-ID:In-Reply-To:References:\n\tFeedback-ID:From:To:Cc:Date:Subject:Reply-To:Feedback-ID:\n\tMessage-ID:BIMI-Selector;\n\tb=N84QNaEBggLAETdFZLsRiZklNVPoTm8WdGqcim//R4/K+ZjKKL6do+DWXBbSPLXSm\n\tISFVdIaJlp7pXCs0QEHPQ5PQIu4roecqVYLEC2d9ChfoCn081+QDgO0zm+h2nnXRWj\n\tWrLrei35E2+BLxSede4avLmtHNkE8OQrkX36PsuBoxzp/Eep5w6a4lHDfZqy3w2yxJ\n\tjqBDWHq6PpVg+TE6qG5VlhbkiD0sV5ULFZksZrabRC2QKdNams4QzBlxrzLjPGicoS\n\t6QIV3KQx531tywWDUdXHuki1hRGaScImAmfh+vSS1K46Sicw4ST4otdFx9S/apVCIj\n\tvrDdpix/TBXgA==","Date":"Wed, 02 Oct 2024 22:26:14 +0000","To":"Kieran Bingham <kieran.bingham@ideasonboard.com>","From":"=?utf-8?q?Barnab=C3=A1s_P=C5=91cze?= <pobrn@protonmail.com>","Cc":"libcamera-devel@lists.libcamera.org","Subject":"Re: [PATCH v1] libcamera: yaml_parser: Take string keys in\n\t`std::string_view`","Message-ID":"<xNcBb6FHnd3KDtJhZYgY10d1DCJUCd0-WpgkAQyiiUvEZGv7A71EmkiBOYig80BWnUHDGBCVEzYKvr-iNI3qP1nj4KnBz2p6J5vvKfR2wG4=@protonmail.com>","In-Reply-To":"<172790598287.2371408.10570747008840571860@ping.linuxembedded.co.uk>","References":"<20241001160329.725278-1-pobrn@protonmail.com>\n\t<172790598287.2371408.10570747008840571860@ping.linuxembedded.co.uk>","Feedback-ID":"20568564:user:proton","X-Pm-Message-ID":"07dc029d1cf10b209fda53ba52972c6d1e3ce221","MIME-Version":"1.0","Content-Type":"text/plain; charset=utf-8","Content-Transfer-Encoding":"quoted-printable","X-BeenThere":"libcamera-devel@lists.libcamera.org","X-Mailman-Version":"2.1.29","Precedence":"list","List-Id":"<libcamera-devel.lists.libcamera.org>","List-Unsubscribe":"<https://lists.libcamera.org/options/libcamera-devel>,\n\t<mailto:libcamera-devel-request@lists.libcamera.org?subject=unsubscribe>","List-Archive":"<https://lists.libcamera.org/pipermail/libcamera-devel/>","List-Post":"<mailto:libcamera-devel@lists.libcamera.org>","List-Help":"<mailto:libcamera-devel-request@lists.libcamera.org?subject=help>","List-Subscribe":"<https://lists.libcamera.org/listinfo/libcamera-devel>,\n\t<mailto:libcamera-devel-request@lists.libcamera.org?subject=subscribe>","Errors-To":"libcamera-devel-bounces@lists.libcamera.org","Sender":"\"libcamera-devel\" <libcamera-devel-bounces@lists.libcamera.org>"}},{"id":31536,"web_url":"https://patchwork.libcamera.org/comment/31536/","msgid":"<20241002223452.GB10359@pendragon.ideasonboard.com>","date":"2024-10-02T22:34:52","subject":"Re: [PATCH v1] libcamera: yaml_parser: Take string keys in\n\t`std::string_view`","submitter":{"id":2,"url":"https://patchwork.libcamera.org/api/people/2/","name":"Laurent Pinchart","email":"laurent.pinchart@ideasonboard.com"},"content":"On Wed, Oct 02, 2024 at 10:53:02PM +0100, Kieran Bingham wrote:\n> Quoting Barnabás Pőcze (2024-10-01 17:03:32)\n> > In many cases a static string literal is used as key. Thus\n> > having the argument type be `const std::string&` is suboptimal\n> > since an `std::string` object needs to be constructed before\n> > the call.\n> > \n> > C++17 introduced `std::string_view`, using which the call\n> > can be done with less overhead, as the `std::string_view`\n> > is non-owning and may be passed in registers entirely.\n> > \n> > So make `YamlObject::{contains,operator[]}` take the string keys\n> > in `std::string_view`s.\n> > \n> > Unfortunately, that is not sufficient yet, because `std::map::find()`\n> > takes an reference to `const key_type`, which would be `const std::string&`\n> > in the case of `YamlParser`. However, with a transparent comparator\n> > such as `std::less<>` `std::map::find()` is able to accept any\n> > object as the argument, and it forwards it to the comparator.\n> > \n> > So make `YamlParser::dictionary_` use `std::less<>` as the comparator\n> > to enable the use of `std::map::find()` with any type of argument.\n> > \n> > Signed-off-by: Barnabás Pőcze <pobrn@protonmail.com>\n> \n> This passes the CI and unit tests at\n> https://gitlab.freedesktop.org/camera/libcamera/-/pipelines/1281981\n> which includes tests covering the yaml-parser.\n> \n> I don't think I would have spotted this ... but it looks and sounds\n> reasonable to me ...\n> \n> Makes me wonder if sometimes we should just use a raw 'const char *'\n> (</me ducks>) ;-) but I think this gives us that with type/length safety\n> on top so seems like a win to me.\n\nstd::string_view is essentially a const char * and a size_t. It's like a\nspan, but with an API optimized for usage with strings. I would have\nsworn it was a C++20 feature, but it looks like I was wrong. We should\nuse it more frequently, for cases where callers have a const char *\n(possibly mixed with std::string) and the callee needs the length of the\nstring. There an overhead when construction a std::string_view from a\nconst char * as the length needs to be determined, so we shouldn't use\nit when the callee doesn't need the length of the string.\n\n> Reviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com>\n\nReviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>\n\n> > ---\n> >  include/libcamera/internal/yaml_parser.h |  7 ++++---\n> >  src/libcamera/yaml_parser.cpp            | 11 ++++-------\n> >  2 files changed, 8 insertions(+), 10 deletions(-)\n> > \n> > diff --git a/include/libcamera/internal/yaml_parser.h b/include/libcamera/internal/yaml_parser.h\n> > index 6211ff4a..de452844 100644\n> > --- a/include/libcamera/internal/yaml_parser.h\n> > +++ b/include/libcamera/internal/yaml_parser.h\n> > @@ -12,6 +12,7 @@\n> >  #include <optional>\n> >  #include <stdint.h>\n> >  #include <string>\n> > +#include <string_view>\n> >  #include <vector>\n> >  \n> >  #include <libcamera/base/class.h>\n> > @@ -206,8 +207,8 @@ public:\n> >  \n> >         const YamlObject &operator[](std::size_t index) const;\n> >  \n> > -       bool contains(const std::string &key) const;\n> > -       const YamlObject &operator[](const std::string &key) const;\n> > +       bool contains(std::string_view key) const;\n> > +       const YamlObject &operator[](std::string_view key) const;\n> >  \n> >  private:\n> >         LIBCAMERA_DISABLE_COPY_AND_MOVE(YamlObject)\n> > @@ -232,7 +233,7 @@ private:\n> >  \n> >         std::string value_;\n> >         Container list_;\n> > -       std::map<std::string, YamlObject *> dictionary_;\n> > +       std::map<std::string, YamlObject *, std::less<>> dictionary_;\n> >  };\n> >  \n> >  class YamlParser final\n> > diff --git a/src/libcamera/yaml_parser.cpp b/src/libcamera/yaml_parser.cpp\n> > index 4784f2dc..7c0b341a 100644\n> > --- a/src/libcamera/yaml_parser.cpp\n> > +++ b/src/libcamera/yaml_parser.cpp\n> > @@ -481,16 +481,13 @@ const YamlObject &YamlObject::operator[](std::size_t index) const\n> >   *\n> >   * \\return True if an element exists, false otherwise\n> >   */\n> > -bool YamlObject::contains(const std::string &key) const\n> > +bool YamlObject::contains(std::string_view key) const\n> >  {\n> > -       if (dictionary_.find(std::ref(key)) == dictionary_.end())\n> > -               return false;\n> > -\n> > -       return true;\n> > +       return dictionary_.find(key) != dictionary_.end();\n> >  }\n> >  \n> >  /**\n> > - * \\fn YamlObject::operator[](const std::string &key) const\n> > + * \\fn YamlObject::operator[](std::string_view key) const\n> >   * \\brief Retrieve a member by name from the dictionary\n> >   *\n> >   * This function retrieve a member of a YamlObject by name. Only YamlObject\n> > @@ -500,7 +497,7 @@ bool YamlObject::contains(const std::string &key) const\n> >   *\n> >   * \\return The YamlObject corresponding to the \\a key member\n> >   */\n> > -const YamlObject &YamlObject::operator[](const std::string &key) const\n> > +const YamlObject &YamlObject::operator[](std::string_view key) const\n> >  {\n> >         if (type_ != Type::Dictionary)\n> >                 return empty;","headers":{"Return-Path":"<libcamera-devel-bounces@lists.libcamera.org>","X-Original-To":"parsemail@patchwork.libcamera.org","Delivered-To":"parsemail@patchwork.libcamera.org","Received":["from lancelot.ideasonboard.com (lancelot.ideasonboard.com\n\t[92.243.16.209])\n\tby patchwork.libcamera.org (Postfix) with ESMTPS id 0CA48C3257\n\tfor <parsemail@patchwork.libcamera.org>;\n\tWed,  2 Oct 2024 22:34:58 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id CCE6363525;\n\tThu,  3 Oct 2024 00:34:56 +0200 (CEST)","from perceval.ideasonboard.com (perceval.ideasonboard.com\n\t[213.167.242.64])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id BA78660553\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tThu,  3 Oct 2024 00:34:55 +0200 (CEST)","from pendragon.ideasonboard.com (81-175-209-231.bb.dnainternet.fi\n\t[81.175.209.231])\n\tby perceval.ideasonboard.com (Postfix) with ESMTPSA id A4A884C7;\n\tThu,  3 Oct 2024 00:33:22 +0200 (CEST)"],"Authentication-Results":"lancelot.ideasonboard.com; dkim=pass (1024-bit key;\n\tunprotected) header.d=ideasonboard.com header.i=@ideasonboard.com\n\theader.b=\"lPMQ8LqN\"; dkim-atps=neutral","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1727908402;\n\tbh=0bZD+582w+iI4vj397drOxEqddBmgRpaLKQ6e8MgO7U=;\n\th=Date:From:To:Cc:Subject:References:In-Reply-To:From;\n\tb=lPMQ8LqNueWqO1o08IjRdoMqrrc2cy8InCGzA3OScP718Ypu/2nM+cVn1dThUXe5x\n\txTb3VoKFwHJ3/iY5VpvxtAiRznXcqVEiscmVud/erZfmNHmWiK7G5BpIol3RnAgbrx\n\t+GCzjbpQP7YVtmd8bFnfA0sUK9TPlYnhsuiMfwvM=","Date":"Thu, 3 Oct 2024 01:34:52 +0300","From":"Laurent Pinchart <laurent.pinchart@ideasonboard.com>","To":"Kieran Bingham <kieran.bingham@ideasonboard.com>","Cc":"=?utf-8?q?Barnab=C3=A1s_P=C5=91cze?= <pobrn@protonmail.com>,\n\tlibcamera-devel@lists.libcamera.org","Subject":"Re: [PATCH v1] libcamera: yaml_parser: Take string keys in\n\t`std::string_view`","Message-ID":"<20241002223452.GB10359@pendragon.ideasonboard.com>","References":"<20241001160329.725278-1-pobrn@protonmail.com>\n\t<172790598287.2371408.10570747008840571860@ping.linuxembedded.co.uk>","MIME-Version":"1.0","Content-Type":"text/plain; charset=utf-8","Content-Disposition":"inline","Content-Transfer-Encoding":"8bit","In-Reply-To":"<172790598287.2371408.10570747008840571860@ping.linuxembedded.co.uk>","X-BeenThere":"libcamera-devel@lists.libcamera.org","X-Mailman-Version":"2.1.29","Precedence":"list","List-Id":"<libcamera-devel.lists.libcamera.org>","List-Unsubscribe":"<https://lists.libcamera.org/options/libcamera-devel>,\n\t<mailto:libcamera-devel-request@lists.libcamera.org?subject=unsubscribe>","List-Archive":"<https://lists.libcamera.org/pipermail/libcamera-devel/>","List-Post":"<mailto:libcamera-devel@lists.libcamera.org>","List-Help":"<mailto:libcamera-devel-request@lists.libcamera.org?subject=help>","List-Subscribe":"<https://lists.libcamera.org/listinfo/libcamera-devel>,\n\t<mailto:libcamera-devel-request@lists.libcamera.org?subject=subscribe>","Errors-To":"libcamera-devel-bounces@lists.libcamera.org","Sender":"\"libcamera-devel\" <libcamera-devel-bounces@lists.libcamera.org>"}}]