Show a patch.

GET /api/patches/23327/?format=api
HTTP 200 OK
Allow: GET, PUT, PATCH, HEAD, OPTIONS
Content-Type: application/json
Vary: Accept

{
    "id": 23327,
    "url": "https://patchwork.libcamera.org/api/patches/23327/?format=api",
    "web_url": "https://patchwork.libcamera.org/patch/23327/",
    "project": {
        "id": 1,
        "url": "https://patchwork.libcamera.org/api/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": "<20250501095818.3996419-4-barnabas.pocze@ideasonboard.com>",
    "date": "2025-05-01T09:58:18",
    "name": "[v2,3/3] libcamera: controls: Expose string controls as `std::string_view`",
    "commit_ref": null,
    "pull_url": null,
    "state": "accepted",
    "archived": false,
    "hash": "afd15d38aff30885125ea0469120af1e407f7f81",
    "submitter": {
        "id": 216,
        "url": "https://patchwork.libcamera.org/api/people/216/?format=api",
        "name": "Barnabás Pőcze",
        "email": "barnabas.pocze@ideasonboard.com"
    },
    "delegate": null,
    "mbox": "https://patchwork.libcamera.org/patch/23327/mbox/",
    "series": [
        {
            "id": 5157,
            "url": "https://patchwork.libcamera.org/api/series/5157/?format=api",
            "web_url": "https://patchwork.libcamera.org/project/libcamera/list/?series=5157",
            "date": "2025-05-01T09:58:15",
            "name": "libcamera: controls: String controls as `std::string_view`",
            "version": 2,
            "mbox": "https://patchwork.libcamera.org/series/5157/mbox/"
        }
    ],
    "comments": "https://patchwork.libcamera.org/api/patches/23327/comments/",
    "check": "pending",
    "checks": "https://patchwork.libcamera.org/api/patches/23327/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 26059BE08B\n\tfor <parsemail@patchwork.libcamera.org>;\n\tThu,  1 May 2025 09:58:29 +0000 (UTC)",
            "from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 13AC268B2A;\n\tThu,  1 May 2025 11:58:26 +0200 (CEST)",
            "from perceval.ideasonboard.com (perceval.ideasonboard.com\n\t[213.167.242.64])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 0F70D68ACC\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tThu,  1 May 2025 11:58:23 +0200 (CEST)",
            "from pb-laptop.local (185.221.143.50.nat.pool.zt.hu\n\t[185.221.143.50])\n\tby perceval.ideasonboard.com (Postfix) with ESMTPSA id 1D5AF2E0\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tThu,  1 May 2025 11:58:16 +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=\"BTllQSLD\"; dkim-atps=neutral",
        "DKIM-Signature": "v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1746093496;\n\tbh=WBa0xeKv3G/nYNsgsAQ9CXl98yMYQjT4vhdFY66hQIU=;\n\th=From:To:Subject:Date:In-Reply-To:References:From;\n\tb=BTllQSLDdHeOGuDDfhmshCOoBeZK3BJ+p5Knp3vUzo0GU/IRQSjrBt8OU/fT5Dd2I\n\tN988LTM/Oknu5GXo/u+5V7M7MtFWH74lqvU5hnKVaVFFy4j1+jMDCH7JerggJFpc/3\n\tz1eYdzLmbMR3PwlvVaHzYIPZNRrLGuG6dHcwxct4=",
        "From": "=?utf-8?q?Barnab=C3=A1s_P=C5=91cze?= <barnabas.pocze@ideasonboard.com>",
        "To": "libcamera-devel@lists.libcamera.org",
        "Subject": "[PATCH v2 3/3] libcamera: controls: Expose string controls as\n\t`std::string_view`",
        "Date": "Thu,  1 May 2025 11:58:18 +0200",
        "Message-ID": "<20250501095818.3996419-4-barnabas.pocze@ideasonboard.com>",
        "X-Mailer": "git-send-email 2.49.0",
        "In-Reply-To": "<20250501095818.3996419-1-barnabas.pocze@ideasonboard.com>",
        "References": "<20250501095818.3996419-1-barnabas.pocze@ideasonboard.com>",
        "MIME-Version": "1.0",
        "Content-Type": "text/plain; charset=UTF-8",
        "Content-Transfer-Encoding": "8bit",
        "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": "When retrieving the value from a `ControlValue` usually one of two\nthings happen: a small, trivially copyable object is returned by\nvalue; or a view into the internal buffer is provided. This is true\nfor everything except strings, which are returned in `std::string`,\nincurring the overhead of string construction.\n\nTo guarantee no potentially \"expensive\" copies, use `std::string_view`\npointing to the internal buffer to return the value. This is similar\nto how other array-like types are returned with a `Span<>`.\n\nThis is an API break, but its scope is limited to just `properties::Model`.\n\nBug: https://bugs.libcamera.org/show_bug.cgi?id=256\nSigned-off-by: Barnabás Pőcze <barnabas.pocze@ideasonboard.com>\n---\n include/libcamera/control_ids.h.in  |  1 +\n include/libcamera/controls.h        | 15 ++++++++-------\n src/apps/cam/capture_script.cpp     |  2 +-\n src/apps/cam/main.cpp               |  2 +-\n src/apps/common/dng_writer.cpp      |  2 +-\n src/apps/qcam/cam_select_dialog.cpp |  6 +++---\n src/py/libcamera/py_helpers.cpp     |  4 ++--\n test/controls/control_value.cpp     |  4 ++--\n utils/codegen/controls.py           |  2 +-\n 9 files changed, 20 insertions(+), 18 deletions(-)",
    "diff": "diff --git a/include/libcamera/control_ids.h.in b/include/libcamera/control_ids.h.in\nindex 5d0594c68..41997f79f 100644\n--- a/include/libcamera/control_ids.h.in\n+++ b/include/libcamera/control_ids.h.in\n@@ -13,6 +13,7 @@\n #include <map>\n #include <stdint.h>\n #include <string>\n+#include <string_view>\n \n #include <libcamera/controls.h>\n \ndiff --git a/include/libcamera/controls.h b/include/libcamera/controls.h\nindex 2ae4ec3d4..5a707a387 100644\n--- a/include/libcamera/controls.h\n+++ b/include/libcamera/controls.h\n@@ -13,6 +13,7 @@\n #include <set>\n #include <stdint.h>\n #include <string>\n+#include <string_view>\n #include <unordered_map>\n #include <vector>\n \n@@ -96,7 +97,7 @@ struct control_type<float> {\n };\n \n template<>\n-struct control_type<std::string> {\n+struct control_type<std::string_view> {\n \tstatic constexpr ControlType value = ControlTypeString;\n \tstatic constexpr std::size_t size = 0;\n };\n@@ -138,7 +139,7 @@ public:\n #ifndef __DOXYGEN__\n \ttemplate<typename T, std::enable_if_t<!details::is_span<T>::value &&\n \t\t\t\t\t      details::control_type<T>::value &&\n-\t\t\t\t\t      !std::is_same<std::string, std::remove_cv_t<T>>::value,\n+\t\t\t\t\t      !std::is_same<std::string_view, std::remove_cv_t<T>>::value,\n \t\t\t\t\t      std::nullptr_t> = nullptr>\n \tControlValue(const T &value)\n \t\t: type_(ControlTypeNone), numElements_(0)\n@@ -148,7 +149,7 @@ public:\n \t}\n \n \ttemplate<typename T, std::enable_if_t<details::is_span<T>::value ||\n-\t\t\t\t\t      std::is_same<std::string, std::remove_cv_t<T>>::value,\n+\t\t\t\t\t      std::is_same<std::string_view, std::remove_cv_t<T>>::value,\n \t\t\t\t\t      std::nullptr_t> = nullptr>\n #else\n \ttemplate<typename T>\n@@ -182,7 +183,7 @@ public:\n \n #ifndef __DOXYGEN__\n \ttemplate<typename T, std::enable_if_t<!details::is_span<T>::value &&\n-\t\t\t\t\t      !std::is_same<std::string, std::remove_cv_t<T>>::value,\n+\t\t\t\t\t      !std::is_same<std::string_view, std::remove_cv_t<T>>::value,\n \t\t\t\t\t      std::nullptr_t> = nullptr>\n \tT get() const\n \t{\n@@ -193,7 +194,7 @@ public:\n \t}\n \n \ttemplate<typename T, std::enable_if_t<details::is_span<T>::value ||\n-\t\t\t\t\t      std::is_same<std::string, std::remove_cv_t<T>>::value,\n+\t\t\t\t\t      std::is_same<std::string_view, std::remove_cv_t<T>>::value,\n \t\t\t\t\t      std::nullptr_t> = nullptr>\n #else\n \ttemplate<typename T>\n@@ -210,7 +211,7 @@ public:\n \n #ifndef __DOXYGEN__\n \ttemplate<typename T, std::enable_if_t<!details::is_span<T>::value &&\n-\t\t\t\t\t      !std::is_same<std::string, std::remove_cv_t<T>>::value,\n+\t\t\t\t\t      !std::is_same<std::string_view, std::remove_cv_t<T>>::value,\n \t\t\t\t\t      std::nullptr_t> = nullptr>\n \tvoid set(const T &value)\n \t{\n@@ -219,7 +220,7 @@ public:\n \t}\n \n \ttemplate<typename T, std::enable_if_t<details::is_span<T>::value ||\n-\t\t\t\t\t      std::is_same<std::string, std::remove_cv_t<T>>::value,\n+\t\t\t\t\t      std::is_same<std::string_view, std::remove_cv_t<T>>::value,\n \t\t\t\t\t      std::nullptr_t> = nullptr>\n #else\n \ttemplate<typename T>\ndiff --git a/src/apps/cam/capture_script.cpp b/src/apps/cam/capture_script.cpp\nindex fdf82efc0..bc4c7c3a0 100644\n--- a/src/apps/cam/capture_script.cpp\n+++ b/src/apps/cam/capture_script.cpp\n@@ -502,7 +502,7 @@ ControlValue CaptureScript::parseScalarControl(const ControlId *id,\n \t\tbreak;\n \t}\n \tcase ControlTypeString: {\n-\t\tvalue.set<std::string>(repr);\n+\t\tvalue.set<std::string_view>(repr);\n \t\tbreak;\n \t}\n \tdefault:\ndiff --git a/src/apps/cam/main.cpp b/src/apps/cam/main.cpp\nindex fa266eca6..157d238d7 100644\n--- a/src/apps/cam/main.cpp\n+++ b/src/apps/cam/main.cpp\n@@ -337,7 +337,7 @@ std::string CamApp::cameraName(const Camera *camera)\n \t\t */\n \t\tconst auto &model = props.get(properties::Model);\n \t\tif (model)\n-\t\t\tname = \"'\" + *model + \"' \";\n+\t\t\tname.append(\"'\").append(*model).append(\"' \");\n \t}\n \n \tname += \"(\" + camera->id() + \")\";\ndiff --git a/src/apps/common/dng_writer.cpp b/src/apps/common/dng_writer.cpp\nindex ac4619511..8d57023e1 100644\n--- a/src/apps/common/dng_writer.cpp\n+++ b/src/apps/common/dng_writer.cpp\n@@ -564,7 +564,7 @@ int DNGWriter::write(const char *filename, const Camera *camera,\n \n \tconst auto &model = cameraProperties.get(properties::Model);\n \tif (model) {\n-\t\tTIFFSetField(tif, TIFFTAG_MODEL, model->c_str());\n+\t\tTIFFSetField(tif, TIFFTAG_MODEL, std::string(*model).c_str());\n \t\t/* \\todo set TIFFTAG_UNIQUECAMERAMODEL. */\n \t}\n \ndiff --git a/src/apps/qcam/cam_select_dialog.cpp b/src/apps/qcam/cam_select_dialog.cpp\nindex 6b6d0713c..9f25ba091 100644\n--- a/src/apps/qcam/cam_select_dialog.cpp\n+++ b/src/apps/qcam/cam_select_dialog.cpp\n@@ -114,8 +114,8 @@ void CameraSelectorDialog::updateCameraInfo(QString cameraId)\n \t\tcameraLocation_->setText(\"Unknown\");\n \t}\n \n-\tconst auto &model = properties.get(libcamera::properties::Model)\n-\t\t\t\t    .value_or(\"Unknown\");\n+\tconst auto model = properties.get(libcamera::properties::Model)\n+\t\t\t\t     .value_or(\"Unknown\");\n \n-\tcameraModel_->setText(QString::fromStdString(model));\n+\tcameraModel_->setText(QString::fromUtf8(model.data(), model.length()));\n }\ndiff --git a/src/py/libcamera/py_helpers.cpp b/src/py/libcamera/py_helpers.cpp\nindex 1ad1d4c1a..8c55ef845 100644\n--- a/src/py/libcamera/py_helpers.cpp\n+++ b/src/py/libcamera/py_helpers.cpp\n@@ -47,7 +47,7 @@ py::object controlValueToPy(const ControlValue &cv)\n \tcase ControlTypeFloat:\n \t\treturn valueOrTuple<float>(cv);\n \tcase ControlTypeString:\n-\t\treturn py::cast(cv.get<std::string>());\n+\t\treturn py::cast(cv.get<std::string_view>());\n \tcase ControlTypeSize: {\n \t\tconst Size *v = reinterpret_cast<const Size *>(cv.data().data());\n \t\treturn py::cast(v);\n@@ -88,7 +88,7 @@ ControlValue pyToControlValue(const py::object &ob, ControlType type)\n \tcase ControlTypeFloat:\n \t\treturn controlValueMaybeArray<float>(ob);\n \tcase ControlTypeString:\n-\t\treturn ControlValue(ob.cast<std::string>());\n+\t\treturn ControlValue(ob.cast<std::string_view>());\n \tcase ControlTypeRectangle:\n \t\treturn controlValueMaybeArray<Rectangle>(ob);\n \tcase ControlTypeSize:\ndiff --git a/test/controls/control_value.cpp b/test/controls/control_value.cpp\nindex 5084fd0cf..032050a77 100644\n--- a/test/controls/control_value.cpp\n+++ b/test/controls/control_value.cpp\n@@ -318,7 +318,7 @@ protected:\n \t\t/*\n \t\t * String type.\n \t\t */\n-\t\tstd::string string{ \"libcamera\" };\n+\t\tstd::string_view string{ \"libcamera\" };\n \t\tvalue.set(string);\n \t\tif (value.isNone() || !value.isArray() ||\n \t\t    value.type() != ControlTypeString ||\n@@ -327,7 +327,7 @@ protected:\n \t\t\treturn TestFail;\n \t\t}\n \n-\t\tif (value.get<std::string>() != string) {\n+\t\tif (value.get<std::string_view>() != string) {\n \t\t\tcerr << \"Control value mismatch after setting to string\" << endl;\n \t\t\treturn TestFail;\n \t\t}\ndiff --git a/utils/codegen/controls.py b/utils/codegen/controls.py\nindex e51610481..9399727bd 100644\n--- a/utils/codegen/controls.py\n+++ b/utils/codegen/controls.py\n@@ -111,7 +111,7 @@ class Control(object):\n         size = self.__data.get('size')\n \n         if typ == 'string':\n-            return 'std::string'\n+            return 'std::string_view'\n \n         if self.__size is None:\n             return typ\n",
    "prefixes": [
        "v2",
        "3/3"
    ]
}