[{"id":791,"web_url":"https://patchwork.libcamera.org/comment/791/","msgid":"<20190212223952.GX6279@pendragon.ideasonboard.com>","date":"2019-02-12T22:39:52","subject":"Re: [libcamera-devel] [PATCH 3/4] libcamera: device_enumerator:\n\tRemove move() on search() return","submitter":{"id":2,"url":"https://patchwork.libcamera.org/api/people/2/","name":"Laurent Pinchart","email":"laurent.pinchart@ideasonboard.com"},"content":"Hi Jacopo,\n\nThank you for the patch.\n\nOn Tue, Feb 12, 2019 at 11:20:20PM +0100, Jacopo Mondi wrote:\n> Remove the std::move() call on the shared_ptr<MediaDevice *> returned by\n> the search() method and remove the std::move() call on temporary return\n> value in pipeline handlers that use the method.\n> \n> Thanks to copy elision, the regular constructor of the newly created\n> object is called, avoiding un-necessary copies.\n> \n> Furthermore, the use of std::move() in the return and assignment\n> statements prevents the compiler from performing copy elision, forcing\n> it to generate two sequences of un-necessary calls to the class'\n> move constructor and destructor.\n> \n> Signed-off-by: Jacopo Mondi <jacopo@jmondi.org>\n\nReviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>\n\n> ---\n>  src/libcamera/device_enumerator.cpp   | 2 +-\n>  src/libcamera/pipeline/ipu3/ipu3.cpp  | 4 ++--\n>  src/libcamera/pipeline/uvcvideo.cpp   | 2 +-\n>  src/libcamera/pipeline/vimc.cpp       | 2 +-\n>  test/v4l2_device/v4l2_device_test.cpp | 2 +-\n>  5 files changed, 6 insertions(+), 6 deletions(-)\n> \n> diff --git a/src/libcamera/device_enumerator.cpp b/src/libcamera/device_enumerator.cpp\n> index 03923b3bb457..7db40812906b 100644\n> --- a/src/libcamera/device_enumerator.cpp\n> +++ b/src/libcamera/device_enumerator.cpp\n> @@ -308,7 +308,7 @@ std::shared_ptr<MediaDevice> DeviceEnumerator::search(const DeviceMatch &dm)\n>  \t\t\tLOG(DeviceEnumerator, Debug)\n>  \t\t\t\t<< \"Successful match for media device \\\"\"\n>  \t\t\t\t<< media->driver() << \"\\\"\";\n> -\t\t\treturn std::move(media);\n> +\t\t\treturn media;\n>  \t\t}\n>  \t}\n>  \n> diff --git a/src/libcamera/pipeline/ipu3/ipu3.cpp b/src/libcamera/pipeline/ipu3/ipu3.cpp\n> index 34b03995ae31..f11e9cc61283 100644\n> --- a/src/libcamera/pipeline/ipu3/ipu3.cpp\n> +++ b/src/libcamera/pipeline/ipu3/ipu3.cpp\n> @@ -279,11 +279,11 @@ bool PipelineHandlerIPU3::match(DeviceEnumerator *enumerator)\n>  \timgu_dm.add(\"ipu3-imgu 1 viewfinder\");\n>  \timgu_dm.add(\"ipu3-imgu 1 3a stat\");\n>  \n> -\tcio2_ = std::move(enumerator->search(cio2_dm));\n> +\tcio2_ = enumerator->search(cio2_dm);\n>  \tif (!cio2_)\n>  \t\treturn false;\n>  \n> -\timgu_ = std::move(enumerator->search(imgu_dm));\n> +\timgu_ = enumerator->search(imgu_dm);\n>  \tif (!imgu_)\n>  \t\treturn false;\n>  \n> diff --git a/src/libcamera/pipeline/uvcvideo.cpp b/src/libcamera/pipeline/uvcvideo.cpp\n> index fc31c52c0ecd..bf0d2fee3851 100644\n> --- a/src/libcamera/pipeline/uvcvideo.cpp\n> +++ b/src/libcamera/pipeline/uvcvideo.cpp\n> @@ -139,7 +139,7 @@ bool PipelineHandlerUVC::match(DeviceEnumerator *enumerator)\n>  {\n>  \tDeviceMatch dm(\"uvcvideo\");\n>  \n> -\tmedia_ = std::move(enumerator->search(dm));\n> +\tmedia_ = enumerator->search(dm);\n>  \n>  \tif (!media_)\n>  \t\treturn false;\n> diff --git a/src/libcamera/pipeline/vimc.cpp b/src/libcamera/pipeline/vimc.cpp\n> index 46840a4f4104..3aed24c3158a 100644\n> --- a/src/libcamera/pipeline/vimc.cpp\n> +++ b/src/libcamera/pipeline/vimc.cpp\n> @@ -148,7 +148,7 @@ bool PipelineHandlerVimc::match(DeviceEnumerator *enumerator)\n>  \tdm.add(\"RGB/YUV Input\");\n>  \tdm.add(\"Scaler\");\n>  \n> -\tmedia_ = std::move(enumerator->search(dm));\n> +\tmedia_ = enumerator->search(dm);\n>  \tif (!media_)\n>  \t\treturn false;\n>  \n> diff --git a/test/v4l2_device/v4l2_device_test.cpp b/test/v4l2_device/v4l2_device_test.cpp\n> index 18d014caf4c8..76f2e55d8cb4 100644\n> --- a/test/v4l2_device/v4l2_device_test.cpp\n> +++ b/test/v4l2_device/v4l2_device_test.cpp\n> @@ -40,7 +40,7 @@ int V4L2DeviceTest::init()\n>  \t}\n>  \n>  \tDeviceMatch dm(\"uvcvideo\");\n> -\tmedia_ = std::move(enumerator_->search(dm));\n> +\tmedia_ = enumerator_->search(dm);\n>  \tif (!media_)\n>  \t\treturn TestSkip;\n>","headers":{"Return-Path":"<laurent.pinchart@ideasonboard.com>","Received":["from perceval.ideasonboard.com (perceval.ideasonboard.com\n\t[213.167.242.64])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 9FABC60B21\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tTue, 12 Feb 2019 23:39:55 +0100 (CET)","from pendragon.ideasonboard.com\n\t(dfj612yhrgyx302h3jwwy-3.rev.dnainternet.fi\n\t[IPv6:2001:14ba:21f5:5b00:ce28:277f:58d7:3ca4])\n\tby perceval.ideasonboard.com (Postfix) with ESMTPSA id 37D7485;\n\tTue, 12 Feb 2019 23:39:55 +0100 (CET)"],"DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1550011195;\n\tbh=o7V+56W/h6qISmcuhKKMdrzr0l1OL/fKk4jctMarW5g=;\n\th=Date:From:To:Cc:Subject:References:In-Reply-To:From;\n\tb=GN3Ww+v2Kjx9/f0ipPQ1z9V8PEJtRjHBOawTsTONU5DzyfxIWkmwwhZUhhLssvk7i\n\tCXr6lqQi76oTFp18xTp1c+G46KiAPbT73ZZogwNFD4Ml5Kh8k5QYnCtEYS33tcEGHx\n\tQ12E7wXK0yuXiZko+8pMkxVTVIdmAsW6jWSfUE+w=","Date":"Wed, 13 Feb 2019 00:39:52 +0200","From":"Laurent Pinchart <laurent.pinchart@ideasonboard.com>","To":"Jacopo Mondi <jacopo@jmondi.org>","Cc":"libcamera-devel@lists.libcamera.org","Message-ID":"<20190212223952.GX6279@pendragon.ideasonboard.com>","References":"<20190212222021.28517-1-jacopo@jmondi.org>\n\t<20190212222021.28517-4-jacopo@jmondi.org>","MIME-Version":"1.0","Content-Type":"text/plain; charset=utf-8","Content-Disposition":"inline","In-Reply-To":"<20190212222021.28517-4-jacopo@jmondi.org>","User-Agent":"Mutt/1.10.1 (2018-07-13)","Subject":"Re: [libcamera-devel] [PATCH 3/4] libcamera: device_enumerator:\n\tRemove move() on search() return","X-BeenThere":"libcamera-devel@lists.libcamera.org","X-Mailman-Version":"2.1.23","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>","X-List-Received-Date":"Tue, 12 Feb 2019 22:39:55 -0000"}},{"id":803,"web_url":"https://patchwork.libcamera.org/comment/803/","msgid":"<20190213110118.GS31044@bigcity.dyn.berto.se>","date":"2019-02-13T11:01:18","subject":"Re: [libcamera-devel] [PATCH 3/4] libcamera: device_enumerator:\n\tRemove move() on search() return","submitter":{"id":5,"url":"https://patchwork.libcamera.org/api/people/5/","name":"Niklas Söderlund","email":"niklas.soderlund@ragnatech.se"},"content":"Hi Jacopo,\n\nThanks for your patch.\n\nOn 2019-02-12 23:20:20 +0100, Jacopo Mondi wrote:\n> Remove the std::move() call on the shared_ptr<MediaDevice *> returned by\n> the search() method and remove the std::move() call on temporary return\n> value in pipeline handlers that use the method.\n> \n> Thanks to copy elision, the regular constructor of the newly created\n> object is called, avoiding un-necessary copies.\n> \n> Furthermore, the use of std::move() in the return and assignment\n> statements prevents the compiler from performing copy elision, forcing\n> it to generate two sequences of un-necessary calls to the class'\n> move constructor and destructor.\n> \n> Signed-off-by: Jacopo Mondi <jacopo@jmondi.org>\n\nReviewed-by: Niklas Söderlund <niklas.soderlund@ragnatech.se>\n\n> ---\n>  src/libcamera/device_enumerator.cpp   | 2 +-\n>  src/libcamera/pipeline/ipu3/ipu3.cpp  | 4 ++--\n>  src/libcamera/pipeline/uvcvideo.cpp   | 2 +-\n>  src/libcamera/pipeline/vimc.cpp       | 2 +-\n>  test/v4l2_device/v4l2_device_test.cpp | 2 +-\n>  5 files changed, 6 insertions(+), 6 deletions(-)\n> \n> diff --git a/src/libcamera/device_enumerator.cpp b/src/libcamera/device_enumerator.cpp\n> index 03923b3bb457..7db40812906b 100644\n> --- a/src/libcamera/device_enumerator.cpp\n> +++ b/src/libcamera/device_enumerator.cpp\n> @@ -308,7 +308,7 @@ std::shared_ptr<MediaDevice> DeviceEnumerator::search(const DeviceMatch &dm)\n>  \t\t\tLOG(DeviceEnumerator, Debug)\n>  \t\t\t\t<< \"Successful match for media device \\\"\"\n>  \t\t\t\t<< media->driver() << \"\\\"\";\n> -\t\t\treturn std::move(media);\n> +\t\t\treturn media;\n>  \t\t}\n>  \t}\n>  \n> diff --git a/src/libcamera/pipeline/ipu3/ipu3.cpp b/src/libcamera/pipeline/ipu3/ipu3.cpp\n> index 34b03995ae31..f11e9cc61283 100644\n> --- a/src/libcamera/pipeline/ipu3/ipu3.cpp\n> +++ b/src/libcamera/pipeline/ipu3/ipu3.cpp\n> @@ -279,11 +279,11 @@ bool PipelineHandlerIPU3::match(DeviceEnumerator *enumerator)\n>  \timgu_dm.add(\"ipu3-imgu 1 viewfinder\");\n>  \timgu_dm.add(\"ipu3-imgu 1 3a stat\");\n>  \n> -\tcio2_ = std::move(enumerator->search(cio2_dm));\n> +\tcio2_ = enumerator->search(cio2_dm);\n>  \tif (!cio2_)\n>  \t\treturn false;\n>  \n> -\timgu_ = std::move(enumerator->search(imgu_dm));\n> +\timgu_ = enumerator->search(imgu_dm);\n>  \tif (!imgu_)\n>  \t\treturn false;\n>  \n> diff --git a/src/libcamera/pipeline/uvcvideo.cpp b/src/libcamera/pipeline/uvcvideo.cpp\n> index fc31c52c0ecd..bf0d2fee3851 100644\n> --- a/src/libcamera/pipeline/uvcvideo.cpp\n> +++ b/src/libcamera/pipeline/uvcvideo.cpp\n> @@ -139,7 +139,7 @@ bool PipelineHandlerUVC::match(DeviceEnumerator *enumerator)\n>  {\n>  \tDeviceMatch dm(\"uvcvideo\");\n>  \n> -\tmedia_ = std::move(enumerator->search(dm));\n> +\tmedia_ = enumerator->search(dm);\n>  \n>  \tif (!media_)\n>  \t\treturn false;\n> diff --git a/src/libcamera/pipeline/vimc.cpp b/src/libcamera/pipeline/vimc.cpp\n> index 46840a4f4104..3aed24c3158a 100644\n> --- a/src/libcamera/pipeline/vimc.cpp\n> +++ b/src/libcamera/pipeline/vimc.cpp\n> @@ -148,7 +148,7 @@ bool PipelineHandlerVimc::match(DeviceEnumerator *enumerator)\n>  \tdm.add(\"RGB/YUV Input\");\n>  \tdm.add(\"Scaler\");\n>  \n> -\tmedia_ = std::move(enumerator->search(dm));\n> +\tmedia_ = enumerator->search(dm);\n>  \tif (!media_)\n>  \t\treturn false;\n>  \n> diff --git a/test/v4l2_device/v4l2_device_test.cpp b/test/v4l2_device/v4l2_device_test.cpp\n> index 18d014caf4c8..76f2e55d8cb4 100644\n> --- a/test/v4l2_device/v4l2_device_test.cpp\n> +++ b/test/v4l2_device/v4l2_device_test.cpp\n> @@ -40,7 +40,7 @@ int V4L2DeviceTest::init()\n>  \t}\n>  \n>  \tDeviceMatch dm(\"uvcvideo\");\n> -\tmedia_ = std::move(enumerator_->search(dm));\n> +\tmedia_ = enumerator_->search(dm);\n>  \tif (!media_)\n>  \t\treturn TestSkip;\n>  \n> -- \n> 2.20.1\n> \n> _______________________________________________\n> libcamera-devel mailing list\n> libcamera-devel@lists.libcamera.org\n> https://lists.libcamera.org/listinfo/libcamera-devel","headers":{"Return-Path":"<niklas.soderlund@ragnatech.se>","Received":["from mail-lj1-x244.google.com (mail-lj1-x244.google.com\n\t[IPv6:2a00:1450:4864:20::244])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id DAB5760DBB\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tWed, 13 Feb 2019 12:01:19 +0100 (CET)","by mail-lj1-x244.google.com with SMTP id e17-v6so1607401lja.8\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tWed, 13 Feb 2019 03:01:19 -0800 (PST)","from localhost (89-233-230-99.cust.bredband2.com. [89.233.230.99])\n\tby smtp.gmail.com with ESMTPSA id\n\tm10-v6sm3350934ljj.34.2019.02.13.03.01.18\n\t(version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256);\n\tWed, 13 Feb 2019 03:01:18 -0800 (PST)"],"DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/relaxed;\n\td=ragnatech-se.20150623.gappssmtp.com; s=20150623;\n\th=date:from:to:cc:subject:message-id:references:mime-version\n\t:content-disposition:content-transfer-encoding:in-reply-to\n\t:user-agent; bh=OsD0FmgTwB/yKWhZstnBRlK0wwRfRHyOTln4XLZ9yRY=;\n\tb=pBKp+OFxRbf6939b1sDAUxAyg4aZNQmTXkRk6UEDA6eNs/MB9O63vSwiXwXuwO8ah/\n\twPiSYeiZQaQ5cLj6AeDMBQj31btnyJbfPAvT5Bs/ym1yTN/e8zn7doR4lVfUZBbjPPej\n\tRi8HR5/6yOBk6/mRLPl2nKp8dw6xpMu7DJip/tnzE2T1aASmAyvcXGcu60KVHg+6P0k+\n\t3Z0bPjCbgN1Q1zZs6EvOUsNhTd0cdlXUvrtLBP7ZJgr+6L7MHbgYczPuNv7Q5ySxV4BL\n\t9hDeFu13Z6BV/ufsfebREy8mSvahqePVbfsjGKzCIaANytdc7Hm4b8i3dGdRf5Xwo/XC\n\t4G3A==","X-Google-DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/relaxed;\n\td=1e100.net; s=20161025;\n\th=x-gm-message-state:date:from:to:cc:subject:message-id:references\n\t:mime-version:content-disposition:content-transfer-encoding\n\t:in-reply-to:user-agent;\n\tbh=OsD0FmgTwB/yKWhZstnBRlK0wwRfRHyOTln4XLZ9yRY=;\n\tb=Y5My3eCF4PpmlzRQhsXH6HWvS+oPp/SLE4I3XAZ5niX7rKr01YLVO9noTiZ32fayKM\n\t7kJkUEZziPXigxA/RPBkxMioMmixrh3aiY4iVNQ3i1nOMB4PAh6p1VPvtQCJEjlSot9R\n\trkKJmpdW1EmFX2HRZNvULbO3O2KXn46gSZTWQwoJODR6+xlAIb4PqM2+HU1ZzFzs2DR3\n\tpFGulbVW0ngww0/fflz6hJA/tAgRfx/YQWhYObgZ51Z1tSPPWXyAXycTN4SLltVR6jw7\n\tvbRcrkn69l+yoKxh568LoZWrncpxLWMRWSN8yxZ8imtnsIeWtAhqzhXI3HgaeT/osPR7\n\tsrKA==","X-Gm-Message-State":"AHQUAuZJC4Z/CP59YRumyh3rTfmskF1Nm5kMpmFse5jGf3MadIlcOW/i\n\tkEFryIV08qIaGw42hTrbDVp/VQ==","X-Google-Smtp-Source":"AHgI3Ib/jdrUEFBrOmORDgXVyZEjAs74JpWbV/t951fQyZKNe8MA/yPBe+9h9bz1IFKZ8nA4iTNhLA==","X-Received":"by 2002:a2e:81c1:: with SMTP id s1mr541733ljg.29.1550055679161; \n\tWed, 13 Feb 2019 03:01:19 -0800 (PST)","Date":"Wed, 13 Feb 2019 12:01:18 +0100","From":"Niklas =?iso-8859-1?q?S=F6derlund?= <niklas.soderlund@ragnatech.se>","To":"Jacopo Mondi <jacopo@jmondi.org>","Cc":"libcamera-devel@lists.libcamera.org","Message-ID":"<20190213110118.GS31044@bigcity.dyn.berto.se>","References":"<20190212222021.28517-1-jacopo@jmondi.org>\n\t<20190212222021.28517-4-jacopo@jmondi.org>","MIME-Version":"1.0","Content-Type":"text/plain; charset=iso-8859-1","Content-Disposition":"inline","Content-Transfer-Encoding":"8bit","In-Reply-To":"<20190212222021.28517-4-jacopo@jmondi.org>","User-Agent":"Mutt/1.10.1 (2018-07-13)","Subject":"Re: [libcamera-devel] [PATCH 3/4] libcamera: device_enumerator:\n\tRemove move() on search() return","X-BeenThere":"libcamera-devel@lists.libcamera.org","X-Mailman-Version":"2.1.23","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>","X-List-Received-Date":"Wed, 13 Feb 2019 11:01:20 -0000"}}]