[v1] libcamera: ipa_module: Avoid unnecessary copy when getting signature
diff mbox series

Message ID 20250421160011.178090-1-barnabas.pocze@ideasonboard.com
State New
Headers show
Series
  • [v1] libcamera: ipa_module: Avoid unnecessary copy when getting signature
Related show

Commit Message

Barnabás Pőcze April 21, 2025, 4 p.m. UTC
The `signature()` getter can just return a reference to the private vector
member variable, and let the caller make a copy if needed. Since the
return type is const qualified, this was likely the original intetion.

Signed-off-by: Barnabás Pőcze <barnabas.pocze@ideasonboard.com>
---
 include/libcamera/internal/ipa_module.h | 2 +-
 src/libcamera/ipa_module.cpp            | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)

Comments

Laurent Pinchart April 21, 2025, 10:01 p.m. UTC | #1
Hi Barnabás,

Thank you for the patch.

On Mon, Apr 21, 2025 at 06:00:11PM +0200, Barnabás Pőcze wrote:
> The `signature()` getter can just return a reference to the private vector
> member variable, and let the caller make a copy if needed. Since the
> return type is const qualified, this was likely the original intetion.

s/intetion/intention/

I wonder if there's a compiler warning flag to report const-qualified
return values.

> Signed-off-by: Barnabás Pőcze <barnabas.pocze@ideasonboard.com>

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

> ---
>  include/libcamera/internal/ipa_module.h | 2 +-
>  src/libcamera/ipa_module.cpp            | 2 +-
>  2 files changed, 2 insertions(+), 2 deletions(-)
> 
> diff --git a/include/libcamera/internal/ipa_module.h b/include/libcamera/internal/ipa_module.h
> index 7c49d3f34..15f19492c 100644
> --- a/include/libcamera/internal/ipa_module.h
> +++ b/include/libcamera/internal/ipa_module.h
> @@ -29,7 +29,7 @@ public:
>  	bool isValid() const;
>  
>  	const struct IPAModuleInfo &info() const;
> -	const std::vector<uint8_t> signature() const;
> +	const std::vector<uint8_t> &signature() const;
>  	const std::string &path() const;
>  
>  	bool load();
> diff --git a/src/libcamera/ipa_module.cpp b/src/libcamera/ipa_module.cpp
> index 9ca74be6e..e6ea61e44 100644
> --- a/src/libcamera/ipa_module.cpp
> +++ b/src/libcamera/ipa_module.cpp
> @@ -373,7 +373,7 @@ const struct IPAModuleInfo &IPAModule::info() const
>   *
>   * \return The IPA module signature
>   */
> -const std::vector<uint8_t> IPAModule::signature() const
> +const std::vector<uint8_t> &IPAModule::signature() const
>  {
>  	return signature_;
>  }

Patch
diff mbox series

diff --git a/include/libcamera/internal/ipa_module.h b/include/libcamera/internal/ipa_module.h
index 7c49d3f34..15f19492c 100644
--- a/include/libcamera/internal/ipa_module.h
+++ b/include/libcamera/internal/ipa_module.h
@@ -29,7 +29,7 @@  public:
 	bool isValid() const;
 
 	const struct IPAModuleInfo &info() const;
-	const std::vector<uint8_t> signature() const;
+	const std::vector<uint8_t> &signature() const;
 	const std::string &path() const;
 
 	bool load();
diff --git a/src/libcamera/ipa_module.cpp b/src/libcamera/ipa_module.cpp
index 9ca74be6e..e6ea61e44 100644
--- a/src/libcamera/ipa_module.cpp
+++ b/src/libcamera/ipa_module.cpp
@@ -373,7 +373,7 @@  const struct IPAModuleInfo &IPAModule::info() const
  *
  * \return The IPA module signature
  */
-const std::vector<uint8_t> IPAModule::signature() const
+const std::vector<uint8_t> &IPAModule::signature() const
 {
 	return signature_;
 }