[RFC,v1,6/7] libcamera: base: log: Pass dynamic prefix through
diff mbox series

Message ID 20250121185554.301901-4-pobrn@protonmail.com
State Superseded
Headers show
Series
  • libcamera: base: log: Misc. changes
Related show

Commit Message

Barnabás Pőcze Jan. 21, 2025, 6:56 p.m. UTC
Use move construction to essentially pass through the string
returned by `Loggable::logPrefix()` to avoid an unnecessary copy.

Signed-off-by: Barnabás Pőcze <pobrn@protonmail.com>
---
 include/libcamera/base/log.h | 2 +-
 src/libcamera/base/log.cpp   | 4 ++--
 2 files changed, 3 insertions(+), 3 deletions(-)

Comments

Laurent Pinchart Jan. 24, 2025, 5:59 p.m. UTC | #1
Hi Barnabás,

Thank you for the patch.

On Tue, Jan 21, 2025 at 06:56:11PM +0000, Barnabás Pőcze wrote:
> Use move construction to essentially pass through the string
> returned by `Loggable::logPrefix()` to avoid an unnecessary copy.
> 
> Signed-off-by: Barnabás Pőcze <pobrn@protonmail.com>

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

> ---
>  include/libcamera/base/log.h | 2 +-
>  src/libcamera/base/log.cpp   | 4 ++--
>  2 files changed, 3 insertions(+), 3 deletions(-)
> 
> diff --git a/include/libcamera/base/log.h b/include/libcamera/base/log.h
> index 9c7775660..ef161bece 100644
> --- a/include/libcamera/base/log.h
> +++ b/include/libcamera/base/log.h
> @@ -64,7 +64,7 @@ class LogMessage
>  public:
>  	LogMessage(const char *fileName, unsigned int line,
>  		   const LogCategory &category, LogSeverity severity,
> -		   const std::string &prefix = std::string());
> +		   std::string prefix = {});
>  
>  	LogMessage(LogMessage &&);
>  	~LogMessage();
> diff --git a/src/libcamera/base/log.cpp b/src/libcamera/base/log.cpp
> index 78db4990c..6430650ec 100644
> --- a/src/libcamera/base/log.cpp
> +++ b/src/libcamera/base/log.cpp
> @@ -873,9 +873,9 @@ const LogCategory &LogCategory::defaultCategory()
>   */
>  LogMessage::LogMessage(const char *fileName, unsigned int line,
>  		       const LogCategory &category, LogSeverity severity,
> -		       const std::string &prefix)
> +		       std::string prefix)
>  	: category_(category), severity_(severity),
> -	  timestamp_(utils::clock::now()), prefix_(prefix)
> +	  timestamp_(utils::clock::now()), prefix_(std::move(prefix))
>  {
>  	std::ostringstream ossFileInfo;
>  	ossFileInfo << utils::basename(fileName) << ":" << line;

Patch
diff mbox series

diff --git a/include/libcamera/base/log.h b/include/libcamera/base/log.h
index 9c7775660..ef161bece 100644
--- a/include/libcamera/base/log.h
+++ b/include/libcamera/base/log.h
@@ -64,7 +64,7 @@  class LogMessage
 public:
 	LogMessage(const char *fileName, unsigned int line,
 		   const LogCategory &category, LogSeverity severity,
-		   const std::string &prefix = std::string());
+		   std::string prefix = {});
 
 	LogMessage(LogMessage &&);
 	~LogMessage();
diff --git a/src/libcamera/base/log.cpp b/src/libcamera/base/log.cpp
index 78db4990c..6430650ec 100644
--- a/src/libcamera/base/log.cpp
+++ b/src/libcamera/base/log.cpp
@@ -873,9 +873,9 @@  const LogCategory &LogCategory::defaultCategory()
  */
 LogMessage::LogMessage(const char *fileName, unsigned int line,
 		       const LogCategory &category, LogSeverity severity,
-		       const std::string &prefix)
+		       std::string prefix)
 	: category_(category), severity_(severity),
-	  timestamp_(utils::clock::now()), prefix_(prefix)
+	  timestamp_(utils::clock::now()), prefix_(std::move(prefix))
 {
 	std::ostringstream ossFileInfo;
 	ossFileInfo << utils::basename(fileName) << ":" << line;