[{"id":33775,"web_url":"https://patchwork.libcamera.org/comment/33775/","msgid":"<174343764344.3394313.17079559316822942999@ping.linuxembedded.co.uk>","date":"2025-03-31T16:14:03","subject":"Re: [PATCH v1] libcamera: camera_manager: Take camera id 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 (2025-03-31 16:09:00)\n> Do not force the caller to have an `std::string` object as a\n> simple string view is sufficient to do the lookup.\n> \n> Signed-off-by: Barnabás Pőcze <barnabas.pocze@ideasonboard.com>\n\nReviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com>\n\n> ---\n>  include/libcamera/camera_manager.h   | 3 ++-\n>  src/libcamera/camera_manager.cpp     | 2 +-\n>  src/py/libcamera/py_camera_manager.h | 2 +-\n>  3 files changed, 4 insertions(+), 3 deletions(-)\n> \n> diff --git a/include/libcamera/camera_manager.h b/include/libcamera/camera_manager.h\n> index b50df7825..27835500f 100644\n> --- a/include/libcamera/camera_manager.h\n> +++ b/include/libcamera/camera_manager.h\n> @@ -9,6 +9,7 @@\n>  \n>  #include <memory>\n>  #include <string>\n> +#include <string_view>\n>  #include <sys/types.h>\n>  #include <vector>\n>  \n> @@ -31,7 +32,7 @@ public:\n>         void stop();\n>  \n>         std::vector<std::shared_ptr<Camera>> cameras() const;\n> -       std::shared_ptr<Camera> get(const std::string &id);\n> +       std::shared_ptr<Camera> get(std::string_view id);\n>  \n>         static const std::string &version() { return version_; }\n>  \n> diff --git a/src/libcamera/camera_manager.cpp b/src/libcamera/camera_manager.cpp\n> index b28bd0bd2..e62e7193c 100644\n> --- a/src/libcamera/camera_manager.cpp\n> +++ b/src/libcamera/camera_manager.cpp\n> @@ -381,7 +381,7 @@ std::vector<std::shared_ptr<Camera>> CameraManager::cameras() const\n>   *\n>   * \\return Shared pointer to Camera object or nullptr if camera not found\n>   */\n> -std::shared_ptr<Camera> CameraManager::get(const std::string &id)\n> +std::shared_ptr<Camera> CameraManager::get(std::string_view id)\n>  {\n>         Private *const d = _d();\n>  \n> diff --git a/src/py/libcamera/py_camera_manager.h b/src/py/libcamera/py_camera_manager.h\n> index 3574db236..af69b915e 100644\n> --- a/src/py/libcamera/py_camera_manager.h\n> +++ b/src/py/libcamera/py_camera_manager.h\n> @@ -20,7 +20,7 @@ public:\n>         ~PyCameraManager();\n>  \n>         pybind11::list cameras();\n> -       std::shared_ptr<Camera> get(const std::string &name) { return cameraManager_->get(name); }\n> +       std::shared_ptr<Camera> get(std::string_view name) { return cameraManager_->get(name); }\n>  \n>         static const std::string &version() { return CameraManager::version(); }\n>  \n> -- \n> 2.49.0\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 F0960C3213\n\tfor <parsemail@patchwork.libcamera.org>;\n\tMon, 31 Mar 2025 16:14:08 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 0664C68981;\n\tMon, 31 Mar 2025 18:14:08 +0200 (CEST)","from perceval.ideasonboard.com (perceval.ideasonboard.com\n\t[IPv6:2001:4b98:dc2:55:216:3eff:fef7:d647])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 4981968967\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tMon, 31 Mar 2025 18:14: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 A8CB7725;\n\tMon, 31 Mar 2025 18:12:14 +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=\"qx/RaHe7\"; dkim-atps=neutral","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1743437534;\n\tbh=iCfDbyl4Kjji0mxYkDDzIdFnCqEShc4ezww98Rh4RAY=;\n\th=In-Reply-To:References:Subject:From:To:Date:From;\n\tb=qx/RaHe7jZbfgaTQqB1FnhwpG/a8f4zmBlzy7P9dD+KCbqzmgzR80dhppnZDkkh60\n\tE+6DP11E2LkD+LoZuvsHF4nmSlQXoX6d7XErfu8B62XlVweaaYVqj6ctJDrQ2FLv3o\n\toslHnxKPjBc+bvMpOAaDVo4QyhGhW9v2j0wAmT80=","Content-Type":"text/plain; charset=\"utf-8\"","MIME-Version":"1.0","Content-Transfer-Encoding":"quoted-printable","In-Reply-To":"<20250331150900.523485-1-barnabas.pocze@ideasonboard.com>","References":"<20250331150900.523485-1-barnabas.pocze@ideasonboard.com>","Subject":"Re: [PATCH v1] libcamera: camera_manager: Take camera id in\n\t`std::string_view`","From":"Kieran Bingham <kieran.bingham@ideasonboard.com>","To":"=?utf-8?q?Barnab=C3=A1s_P=C5=91cze?= <barnabas.pocze@ideasonboard.com>,\n\tlibcamera-devel@lists.libcamera.org","Date":"Mon, 31 Mar 2025 17:14:03 +0100","Message-ID":"<174343764344.3394313.17079559316822942999@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":33778,"web_url":"https://patchwork.libcamera.org/comment/33778/","msgid":"<20250331162635.GF14432@pendragon.ideasonboard.com>","date":"2025-03-31T16:26:35","subject":"Re: [PATCH v1] libcamera: camera_manager: Take camera id 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 Mon, Mar 31, 2025 at 05:14:03PM +0100, Kieran Bingham wrote:\n> Quoting Barnabás Pőcze (2025-03-31 16:09:00)\n> > Do not force the caller to have an `std::string` object as a\n> > simple string view is sufficient to do the lookup.\n> > \n> > Signed-off-by: Barnabás Pőcze <barnabas.pocze@ideasonboard.com>\n> \n> Reviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com>\n\nI still dislike how C++ requires the internal implementation of a\nfunction to be taken into account to select the right type of string\nargument, but in this case I can't imagine a use case where\nCameraManager::get() would be implemented with a need to copy the\nstring. std::string_view should be a safe future-proof pick.\n\nReviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>\n\n> > ---\n> >  include/libcamera/camera_manager.h   | 3 ++-\n> >  src/libcamera/camera_manager.cpp     | 2 +-\n> >  src/py/libcamera/py_camera_manager.h | 2 +-\n> >  3 files changed, 4 insertions(+), 3 deletions(-)\n> > \n> > diff --git a/include/libcamera/camera_manager.h b/include/libcamera/camera_manager.h\n> > index b50df7825..27835500f 100644\n> > --- a/include/libcamera/camera_manager.h\n> > +++ b/include/libcamera/camera_manager.h\n> > @@ -9,6 +9,7 @@\n> >  \n> >  #include <memory>\n> >  #include <string>\n> > +#include <string_view>\n> >  #include <sys/types.h>\n> >  #include <vector>\n> >  \n> > @@ -31,7 +32,7 @@ public:\n> >         void stop();\n> >  \n> >         std::vector<std::shared_ptr<Camera>> cameras() const;\n> > -       std::shared_ptr<Camera> get(const std::string &id);\n> > +       std::shared_ptr<Camera> get(std::string_view id);\n> >  \n> >         static const std::string &version() { return version_; }\n> >  \n> > diff --git a/src/libcamera/camera_manager.cpp b/src/libcamera/camera_manager.cpp\n> > index b28bd0bd2..e62e7193c 100644\n> > --- a/src/libcamera/camera_manager.cpp\n> > +++ b/src/libcamera/camera_manager.cpp\n> > @@ -381,7 +381,7 @@ std::vector<std::shared_ptr<Camera>> CameraManager::cameras() const\n> >   *\n> >   * \\return Shared pointer to Camera object or nullptr if camera not found\n> >   */\n> > -std::shared_ptr<Camera> CameraManager::get(const std::string &id)\n> > +std::shared_ptr<Camera> CameraManager::get(std::string_view id)\n> >  {\n> >         Private *const d = _d();\n> >  \n> > diff --git a/src/py/libcamera/py_camera_manager.h b/src/py/libcamera/py_camera_manager.h\n> > index 3574db236..af69b915e 100644\n> > --- a/src/py/libcamera/py_camera_manager.h\n> > +++ b/src/py/libcamera/py_camera_manager.h\n> > @@ -20,7 +20,7 @@ public:\n> >         ~PyCameraManager();\n> >  \n> >         pybind11::list cameras();\n> > -       std::shared_ptr<Camera> get(const std::string &name) { return cameraManager_->get(name); }\n> > +       std::shared_ptr<Camera> get(std::string_view name) { return cameraManager_->get(name); }\n> >  \n> >         static const std::string &version() { return CameraManager::version(); }\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 053DEC3213\n\tfor <parsemail@patchwork.libcamera.org>;\n\tMon, 31 Mar 2025 16:27:02 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id CCA4A68986;\n\tMon, 31 Mar 2025 18:27:00 +0200 (CEST)","from perceval.ideasonboard.com (perceval.ideasonboard.com\n\t[213.167.242.64])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 6680568967\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tMon, 31 Mar 2025 18:26:59 +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 90D2A725;\n\tMon, 31 Mar 2025 18:25:07 +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=\"hF4qqHtG\"; dkim-atps=neutral","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1743438307;\n\tbh=iesb45T+IJrif/OxKhe0oS3D2VCFgWJH7GvuRfRdSRU=;\n\th=Date:From:To:Cc:Subject:References:In-Reply-To:From;\n\tb=hF4qqHtGxk+52RMDpXuJ5DyjdSbCO7r3Tbz7qN+LzZviGRsn05bzfH7Q/aJHqaHIG\n\tthSMYWhblF1kSucC+RUOhKsW9aMnAiLmMJuikX0CcF1PJMP1niGeMrg3vwtSAOvpJt\n\tqp2ebcTVEMSzKyyxWQ1UuTjmAqLlLAmv29P/2VlE=","Date":"Mon, 31 Mar 2025 19:26:35 +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?= <barnabas.pocze@ideasonboard.com>,\n\tlibcamera-devel@lists.libcamera.org","Subject":"Re: [PATCH v1] libcamera: camera_manager: Take camera id in\n\t`std::string_view`","Message-ID":"<20250331162635.GF14432@pendragon.ideasonboard.com>","References":"<20250331150900.523485-1-barnabas.pocze@ideasonboard.com>\n\t<174343764344.3394313.17079559316822942999@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":"<174343764344.3394313.17079559316822942999@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>"}}]