[v4,6/8] libcamera: base: log: Pass dynamic prefix through
diff mbox series

Message ID 20250225173531.2595922-7-pobrn@protonmail.com
State Accepted
Headers show
Series
  • libcamera: base: log: Misc. changes
Related show

Commit Message

Barnabás Pőcze Feb. 25, 2025, 5:36 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>
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(-)

Comments

Jacopo Mondi Feb. 26, 2025, 7:52 a.m. UTC | #1
Hi Barnabás

On Tue, Feb 25, 2025 at 05:36:10PM +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>

Reviewed-by: Jacopo Mondi <jacopo.mondi@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 acef24203..1fb92603f 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();
>
>  	std::ostream &stream() { return msgStream_; }
> diff --git a/src/libcamera/base/log.cpp b/src/libcamera/base/log.cpp
> index c0e0be60f..6687deb93 100644
> --- a/src/libcamera/base/log.cpp
> +++ b/src/libcamera/base/log.cpp
> @@ -858,11 +858,11 @@ 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()),
>  	  fileInfo_((std::ostringstream() << utils::basename(fileName) << ":" << line).str()),
> -	  prefix_(prefix)
> +	  prefix_(std::move(prefix))
>  {
>  }
>
> --
> 2.48.1
>
>

Patch
diff mbox series

diff --git a/include/libcamera/base/log.h b/include/libcamera/base/log.h
index acef24203..1fb92603f 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();
 
 	std::ostream &stream() { return msgStream_; }
diff --git a/src/libcamera/base/log.cpp b/src/libcamera/base/log.cpp
index c0e0be60f..6687deb93 100644
--- a/src/libcamera/base/log.cpp
+++ b/src/libcamera/base/log.cpp
@@ -858,11 +858,11 @@  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()),
 	  fileInfo_((std::ostringstream() << utils::basename(fileName) << ":" << line).str()),
-	  prefix_(prefix)
+	  prefix_(std::move(prefix))
 {
 }