[{"id":28976,"web_url":"https://patchwork.libcamera.org/comment/28976/","msgid":"<171049925034.1011926.15922775669483463775@ping.linuxembedded.co.uk>","date":"2024-03-15T10:40:50","subject":"Re: [PATCH v2 08/14] libcamera: v4l2_subdevice: Replace\n\tRouting::toString() with operator<<()","submitter":{"id":4,"url":"https://patchwork.libcamera.org/api/people/4/","name":"Kieran Bingham","email":"kieran.bingham@ideasonboard.com"},"content":"Quoting Laurent Pinchart (2024-03-15 00:16:07)\n> The main (and only at the moment) use case for the Routing::toString()\n> function is to print a representation of the routing table in a log\n> message. The function is implemented using an std::stringstream, and the\n> returned std::string is then inserted into an std::ostream. This is\n> inefficient. Replace the function with a specialization of the\n> operator<<() and use it in the caller.\n> \n> Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>\n> Reviewed-by: Jacopo Mondi <jacopo.mondi@ideasonboard.com>\n\n\nReviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com>\n\n> ---\n>  include/libcamera/internal/v4l2_subdevice.h |  7 ++---\n>  src/libcamera/pipeline/simple/simple.cpp    |  2 +-\n>  src/libcamera/v4l2_subdevice.cpp            | 29 +++++++++++----------\n>  3 files changed, 18 insertions(+), 20 deletions(-)\n> \n> diff --git a/include/libcamera/internal/v4l2_subdevice.h b/include/libcamera/internal/v4l2_subdevice.h\n> index 6cd36730371a..2939dc2411c6 100644\n> --- a/include/libcamera/internal/v4l2_subdevice.h\n> +++ b/include/libcamera/internal/v4l2_subdevice.h\n> @@ -95,11 +95,7 @@ public:\n>                 unsigned int stream;\n>         };\n>  \n> -       class Routing : public std::vector<struct v4l2_subdev_route>\n> -       {\n> -       public:\n> -               std::string toString() const;\n> -       };\n> +       using Routing = std::vector<struct v4l2_subdev_route>;\n>  \n>         explicit V4L2Subdevice(const MediaEntity *entity);\n>         ~V4L2Subdevice();\n> @@ -178,5 +174,6 @@ static inline bool operator!=(const V4L2Subdevice::Stream &lhs,\n>  }\n>  \n>  std::ostream &operator<<(std::ostream &out, const V4L2Subdevice::Stream &stream);\n> +std::ostream &operator<<(std::ostream &out, const V4L2Subdevice::Routing &routing);\n>  \n>  } /* namespace libcamera */\n> diff --git a/src/libcamera/pipeline/simple/simple.cpp b/src/libcamera/pipeline/simple/simple.cpp\n> index 3d0424969a89..feea26fd124f 100644\n> --- a/src/libcamera/pipeline/simple/simple.cpp\n> +++ b/src/libcamera/pipeline/simple/simple.cpp\n> @@ -1388,7 +1388,7 @@ int SimplePipelineHandler::resetRoutingTable(V4L2Subdevice *subdev)\n>  \n>         LOG(SimplePipeline, Debug)\n>                 << \"Routing table of \" << subdev->deviceNode()\n> -               << \" reset to \" << routing.toString();\n> +               << \" reset to \" << routing;\n>  \n>         return 0;\n>  }\n> diff --git a/src/libcamera/v4l2_subdevice.cpp b/src/libcamera/v4l2_subdevice.cpp\n> index cc079425bb16..deef681e0d3a 100644\n> --- a/src/libcamera/v4l2_subdevice.cpp\n> +++ b/src/libcamera/v4l2_subdevice.cpp\n> @@ -899,30 +899,31 @@ std::ostream &operator<<(std::ostream &out, const V4L2Subdevice::Stream &stream)\n>  }\n>  \n>  /**\n> - * \\class V4L2Subdevice::Routing\n> + * \\typedef V4L2Subdevice::Routing\n>   * \\brief V4L2 subdevice routing table\n>   *\n>   * This class stores a subdevice routing table as a vector of routes.\n>   */\n>  \n>  /**\n> - * \\brief Assemble and return a string describing the routing table\n> - * \\return A string describing the routing table\n> + * \\brief Insert a text representation of a V4L2Subdevice::Routing into an\n> + *     output stream\n> + * \\param[in] out The output stream\n> + * \\param[in] routing The V4L2Subdevice::Routing\n> + * \\return The output stream \\a out\n>   */\n> -std::string V4L2Subdevice::Routing::toString() const\n> +std::ostream &operator<<(std::ostream &out, const V4L2Subdevice::Routing &routing)\n>  {\n> -       std::stringstream routing;\n> -\n> -       for (const auto &[i, route] : utils::enumerate(*this)) {\n> -               routing << \"[\" << i << \"] \"\n> -                       << route.sink_pad << \"/\" << route.sink_stream << \" -> \"\n> -                       << route.source_pad << \"/\" << route.source_stream\n> -                       << \" (\" << utils::hex(route.flags) << \")\";\n> -               if (i != size() - 1)\n> -                       routing << \", \";\n> +       for (const auto &[i, route] : utils::enumerate(routing)) {\n> +               out << \"[\" << i << \"] \"\n> +                   << route.sink_pad << \"/\" << route.sink_stream << \" -> \"\n> +                   << route.source_pad << \"/\" << route.source_stream\n> +                   << \" (\" << utils::hex(route.flags) << \")\";\n> +               if (i != routing.size() - 1)\n> +                       out << \", \";\n>         }\n>  \n> -       return routing.str();\n> +       return out;\n>  }\n>  \n>  /**\n> -- \n> Regards,\n> \n> Laurent Pinchart\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 BE1CFBD160\n\tfor <parsemail@patchwork.libcamera.org>;\n\tFri, 15 Mar 2024 10:40:54 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 71DC362C8C;\n\tFri, 15 Mar 2024 11:40:54 +0100 (CET)","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 18BD16295D\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tFri, 15 Mar 2024 11:40:53 +0100 (CET)","from pendragon.ideasonboard.com\n\t(aztw-30-b2-v4wan-166917-cust845.vm26.cable.virginm.net\n\t[82.37.23.78])\n\tby perceval.ideasonboard.com (Postfix) with ESMTPSA id 43692B3;\n\tFri, 15 Mar 2024 11:40:29 +0100 (CET)"],"Authentication-Results":"lancelot.ideasonboard.com; dkim=pass (1024-bit key;\n\tunprotected) header.d=ideasonboard.com header.i=@ideasonboard.com\n\theader.b=\"dH8vQePJ\"; dkim-atps=neutral","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1710499229;\n\tbh=KCNniJissmqrtcyZs8wGCQokG9mDYJVuvpn4jnd7fuU=;\n\th=In-Reply-To:References:Subject:From:To:Date:From;\n\tb=dH8vQePJQe6m71tSxwK3lkHZaoUbdKEtnTiH8OYElppX9IEaQkdsm4Wenye3OCwzq\n\tyXFt5A2MzAmwh6QfSVE3UvQMYIG+LfJSCUxE2TbqcNeSoQebrnLFvOklYA+Df+R6gE\n\tK9yWHlyJomFjnyXQC0qE+rEFOjXykMgdCygbN0s0=","Content-Type":"text/plain; charset=\"utf-8\"","MIME-Version":"1.0","Content-Transfer-Encoding":"quoted-printable","In-Reply-To":"<20240315001613.2033-9-laurent.pinchart@ideasonboard.com>","References":"<20240315001613.2033-1-laurent.pinchart@ideasonboard.com>\n\t<20240315001613.2033-9-laurent.pinchart@ideasonboard.com>","Subject":"Re: [PATCH v2 08/14] libcamera: v4l2_subdevice: Replace\n\tRouting::toString() with operator<<()","From":"Kieran Bingham <kieran.bingham@ideasonboard.com>","To":"Laurent Pinchart <laurent.pinchart@ideasonboard.com>,\n\tlibcamera-devel@lists.libcamera.org","Date":"Fri, 15 Mar 2024 10:40:50 +0000","Message-ID":"<171049925034.1011926.15922775669483463775@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>"}}]