[1/6] ipa: rpi: Use r-value references in the set()/setLocked() functions
diff mbox series

Message ID 20241213094602.2083174-2-naush@raspberrypi.com
State New
Headers show
Series
  • Raspberry Pi: Various changes
Related show

Commit Message

Naushir Patuck Dec. 13, 2024, 9:38 a.m. UTC
Use an r-value reference in set() and setLocked(), allowing more
efficient metadata handling with std::forward and std::move if needed.

Signed-off-by: Naushir Patuck <naush@raspberrypi.com>
---
 src/ipa/rpi/controller/metadata.h | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

Comments

David Plowman Dec. 13, 2024, 10:03 a.m. UTC | #1
Hi Naush

Thanks for the patch.

On Fri, 13 Dec 2024 at 09:46, Naushir Patuck <naush@raspberrypi.com> wrote:
>
> Use an r-value reference in set() and setLocked(), allowing more
> efficient metadata handling with std::forward and std::move if needed.
>
> Signed-off-by: Naushir Patuck <naush@raspberrypi.com>

Looks good!

Reviewed-by: David Plowman <david.plowman@raspberrypi.com>

Thanks
David

> ---
>  src/ipa/rpi/controller/metadata.h | 8 ++++----
>  1 file changed, 4 insertions(+), 4 deletions(-)
>
> diff --git a/src/ipa/rpi/controller/metadata.h b/src/ipa/rpi/controller/metadata.h
> index b4650d25170f..eda4b59bca9a 100644
> --- a/src/ipa/rpi/controller/metadata.h
> +++ b/src/ipa/rpi/controller/metadata.h
> @@ -36,10 +36,10 @@ public:
>         }
>
>         template<typename T>
> -       void set(std::string const &tag, T const &value)
> +       void set(std::string const &tag, T &&value)
>         {
>                 std::scoped_lock lock(mutex_);
> -               data_[tag] = value;
> +               data_[tag] = std::forward<T>(value);
>         }
>
>         template<typename T>
> @@ -104,10 +104,10 @@ public:
>         }
>
>         template<typename T>
> -       void setLocked(std::string const &tag, T const &value)
> +       void setLocked(std::string const &tag, T &&value)
>         {
>                 /* Use this only if you're holding the lock yourself. */
> -               data_[tag] = value;
> +               data_[tag] = std::forward<T>(value);
>         }
>
>         /*
> --
> 2.43.0
>
Laurent Pinchart Dec. 15, 2024, 3:33 p.m. UTC | #2
Hi Naush,

Thank you for the patch.

On Fri, Dec 13, 2024 at 09:38:24AM +0000, Naushir Patuck wrote:
> Use an r-value reference in set() and setLocked(), allowing more
> efficient metadata handling with std::forward and std::move if needed.
> 
> Signed-off-by: Naushir Patuck <naush@raspberrypi.com>
> ---
>  src/ipa/rpi/controller/metadata.h | 8 ++++----
>  1 file changed, 4 insertions(+), 4 deletions(-)
> 
> diff --git a/src/ipa/rpi/controller/metadata.h b/src/ipa/rpi/controller/metadata.h
> index b4650d25170f..eda4b59bca9a 100644
> --- a/src/ipa/rpi/controller/metadata.h
> +++ b/src/ipa/rpi/controller/metadata.h
> @@ -36,10 +36,10 @@ public:
>  	}
>  
>  	template<typename T>
> -	void set(std::string const &tag, T const &value)
> +	void set(std::string const &tag, T &&value)
>  	{
>  		std::scoped_lock lock(mutex_);
> -		data_[tag] = value;
> +		data_[tag] = std::forward<T>(value);

You should include <utility>. With that,

Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>

>  	}
>  
>  	template<typename T>
> @@ -104,10 +104,10 @@ public:
>  	}
>  
>  	template<typename T>
> -	void setLocked(std::string const &tag, T const &value)
> +	void setLocked(std::string const &tag, T &&value)
>  	{
>  		/* Use this only if you're holding the lock yourself. */
> -		data_[tag] = value;
> +		data_[tag] = std::forward<T>(value);
>  	}
>  
>  	/*

Patch
diff mbox series

diff --git a/src/ipa/rpi/controller/metadata.h b/src/ipa/rpi/controller/metadata.h
index b4650d25170f..eda4b59bca9a 100644
--- a/src/ipa/rpi/controller/metadata.h
+++ b/src/ipa/rpi/controller/metadata.h
@@ -36,10 +36,10 @@  public:
 	}
 
 	template<typename T>
-	void set(std::string const &tag, T const &value)
+	void set(std::string const &tag, T &&value)
 	{
 		std::scoped_lock lock(mutex_);
-		data_[tag] = value;
+		data_[tag] = std::forward<T>(value);
 	}
 
 	template<typename T>
@@ -104,10 +104,10 @@  public:
 	}
 
 	template<typename T>
-	void setLocked(std::string const &tag, T const &value)
+	void setLocked(std::string const &tag, T &&value)
 	{
 		/* Use this only if you're holding the lock yourself. */
-		data_[tag] = value;
+		data_[tag] = std::forward<T>(value);
 	}
 
 	/*