Patch Detail
Show a patch.
GET /api/1.1/patches/21464/?format=api
{ "id": 21464, "url": "https://patchwork.libcamera.org/api/1.1/patches/21464/?format=api", "web_url": "https://patchwork.libcamera.org/patch/21464/", "project": { "id": 1, "url": "https://patchwork.libcamera.org/api/1.1/projects/1/?format=api", "name": "libcamera", "link_name": "libcamera", "list_id": "libcamera_core", "list_email": "libcamera-devel@lists.libcamera.org", "web_url": "", "scm_url": "", "webscm_url": "" }, "msgid": "<20241001160329.725278-1-pobrn@protonmail.com>", "date": "2024-10-01T16:03:32", "name": "[v1] libcamera: yaml_parser: Take string keys in `std::string_view`", "commit_ref": "e879a86979ab368cd3744bd82fdc7c3013685f0f", "pull_url": null, "state": "accepted", "archived": false, "hash": "a539a85d94931be2c948820327cd775fcb146049", "submitter": { "id": 133, "url": "https://patchwork.libcamera.org/api/1.1/people/133/?format=api", "name": "Pőcze Barnabás", "email": "pobrn@protonmail.com" }, "delegate": null, "mbox": "https://patchwork.libcamera.org/patch/21464/mbox/", "series": [ { "id": 4646, "url": "https://patchwork.libcamera.org/api/1.1/series/4646/?format=api", "web_url": "https://patchwork.libcamera.org/project/libcamera/list/?series=4646", "date": "2024-10-01T16:03:32", "name": "[v1] libcamera: yaml_parser: Take string keys in `std::string_view`", "version": 1, "mbox": "https://patchwork.libcamera.org/series/4646/mbox/" } ], "comments": "https://patchwork.libcamera.org/api/patches/21464/comments/", "check": "pending", "checks": "https://patchwork.libcamera.org/api/patches/21464/checks/", "tags": {}, "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 67FDFBD80A\n\tfor <parsemail@patchwork.libcamera.org>;\n\tTue, 1 Oct 2024 16:03:41 +0000 (UTC)", "from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 0B59E6351F;\n\tTue, 1 Oct 2024 18:03:40 +0200 (CEST)", "from mail-40131.protonmail.ch (mail-40131.protonmail.ch\n\t[185.70.40.131])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id DC5FE60553\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tTue, 1 Oct 2024 18:03:37 +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=\"sLLqa/FZ\"; dkim-atps=neutral", "DKIM-Signature": "v=1; a=rsa-sha256; c=relaxed/relaxed; d=protonmail.com;\n\ts=protonmail3; t=1727798617; x=1728057817;\n\tbh=7mvWqoyVvh6aH3WnfwLU45+LJ8ciuxTe4XhsXdm+Mwk=;\n\th=Date:To:From:Subject:Message-ID:Feedback-ID:From:To:Cc:Date:\n\tSubject:Reply-To:Feedback-ID:Message-ID:BIMI-Selector;\n\tb=sLLqa/FZVr5eGkE+TgytV/pUNT6r7M1cTS2KHLTQO8QiJ+brPjXFSi4L9szHSQCxp\n\tK52fl7slztZGjo3P1xnp7rgl/RleNNXGM5SI+IQFTWmpAIhKmpzbDluxdVJ8vFKTA2\n\t5RnHwSTMG67UVDYmx2qQIFqfNcNBZ78FkcTlrvg74kCciFLn2z7aUN/YzwDXhfdeU3\n\tSa1/gcBRz7ofpdIdk0Mo6mv4FBIbTxxXaXDpnyNOGaFY5tOc6xfcGy6VuwBAa41vuh\n\tCej1KHuItY+bh/DflZW/es7FtROmYlg9c4so1QataBX8B5ZyFqT+5abN3X2yF/V5HS\n\t5Tv7u+c+rODkA==", "Date": "Tue, 01 Oct 2024 16:03:32 +0000", "To": "libcamera-devel@lists.libcamera.org", "From": "=?utf-8?q?Barnab=C3=A1s_P=C5=91cze?= <pobrn@protonmail.com>", "Subject": "[PATCH v1] libcamera: yaml_parser: Take string keys in\n\t`std::string_view`", "Message-ID": "<20241001160329.725278-1-pobrn@protonmail.com>", "Feedback-ID": "20568564:user:proton", "X-Pm-Message-ID": "2a2285386b5b833cd19048f6b90b2dafd709e3ee", "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>" }, "content": "In many cases a static string literal is used as key. Thus\nhaving the argument type be `const std::string&` is suboptimal\nsince an `std::string` object needs to be constructed before\nthe call.\n\nC++17 introduced `std::string_view`, using which the call\ncan be done with less overhead, as the `std::string_view`\nis non-owning and may be passed in registers entirely.\n\nSo make `YamlObject::{contains,operator[]}` take the string keys\nin `std::string_view`s.\n\nUnfortunately, that is not sufficient yet, because `std::map::find()`\ntakes an reference to `const key_type`, which would be `const std::string&`\nin the case of `YamlParser`. However, with a transparent comparator\nsuch as `std::less<>` `std::map::find()` is able to accept any\nobject as the argument, and it forwards it to the comparator.\n\nSo make `YamlParser::dictionary_` use `std::less<>` as the comparator\nto enable the use of `std::map::find()` with any type of argument.\n\nSigned-off-by: Barnabás Pőcze <pobrn@protonmail.com>\n---\n include/libcamera/internal/yaml_parser.h | 7 ++++---\n src/libcamera/yaml_parser.cpp | 11 ++++-------\n 2 files changed, 8 insertions(+), 10 deletions(-)", "diff": "diff --git a/include/libcamera/internal/yaml_parser.h b/include/libcamera/internal/yaml_parser.h\nindex 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 \tconst YamlObject &operator[](std::size_t index) const;\n \n-\tbool contains(const std::string &key) const;\n-\tconst YamlObject &operator[](const std::string &key) const;\n+\tbool contains(std::string_view key) const;\n+\tconst YamlObject &operator[](std::string_view key) const;\n \n private:\n \tLIBCAMERA_DISABLE_COPY_AND_MOVE(YamlObject)\n@@ -232,7 +233,7 @@ private:\n \n \tstd::string value_;\n \tContainer list_;\n-\tstd::map<std::string, YamlObject *> dictionary_;\n+\tstd::map<std::string, YamlObject *, std::less<>> dictionary_;\n };\n \n class YamlParser final\ndiff --git a/src/libcamera/yaml_parser.cpp b/src/libcamera/yaml_parser.cpp\nindex 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-\tif (dictionary_.find(std::ref(key)) == dictionary_.end())\n-\t\treturn false;\n-\n-\treturn true;\n+\treturn 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 \tif (type_ != Type::Dictionary)\n \t\treturn empty;\n", "prefixes": [ "v1" ] }