[RFC,v1,1/7] libcamera: base: log: Move all fields of `LogMessage`
diff mbox series

Message ID 20250121185044.300816-2-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:50 p.m. UTC
Move all fields of `LogMessage` in the move constructor.

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

Comments

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

Thank you for the patch.

On Tue, Jan 21, 2025 at 06:50:52PM +0000, Barnabás Pőcze wrote:
> Move all fields of `LogMessage` in the move constructor.
> 
> Signed-off-by: Barnabás Pőcze <pobrn@protonmail.com>

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

but given that C++17 enforces copy elision, I think we could drop this
function completely (see the comment just above it).

> ---
>  src/libcamera/base/log.cpp | 6 ++++--
>  1 file changed, 4 insertions(+), 2 deletions(-)
> 
> diff --git a/src/libcamera/base/log.cpp b/src/libcamera/base/log.cpp
> index 3a656b8f0..61a43d525 100644
> --- a/src/libcamera/base/log.cpp
> +++ b/src/libcamera/base/log.cpp
> @@ -17,6 +17,7 @@
>  #include <syslog.h>
>  #include <time.h>
>  #include <unordered_set>
> +#include <utility>
>  
>  #include <libcamera/logging.h>
>  
> @@ -894,9 +895,10 @@ LogMessage::LogMessage(const char *fileName, unsigned int line,
>   */
>  LogMessage::LogMessage(LogMessage &&other)
>  	: msgStream_(std::move(other.msgStream_)), category_(other.category_),
> -	  severity_(other.severity_)
> +	  severity_(std::exchange(other.severity_, LogInvalid)),
> +	  timestamp_(other.timestamp_), fileInfo_(std::move(other.fileInfo_)),
> +	  prefix_(std::move(other.prefix_))
>  {
> -	other.severity_ = LogInvalid;
>  }
>  
>  void LogMessage::init(const char *fileName, unsigned int line)

Patch
diff mbox series

diff --git a/src/libcamera/base/log.cpp b/src/libcamera/base/log.cpp
index 3a656b8f0..61a43d525 100644
--- a/src/libcamera/base/log.cpp
+++ b/src/libcamera/base/log.cpp
@@ -17,6 +17,7 @@ 
 #include <syslog.h>
 #include <time.h>
 #include <unordered_set>
+#include <utility>
 
 #include <libcamera/logging.h>
 
@@ -894,9 +895,10 @@  LogMessage::LogMessage(const char *fileName, unsigned int line,
  */
 LogMessage::LogMessage(LogMessage &&other)
 	: msgStream_(std::move(other.msgStream_)), category_(other.category_),
-	  severity_(other.severity_)
+	  severity_(std::exchange(other.severity_, LogInvalid)),
+	  timestamp_(other.timestamp_), fileInfo_(std::move(other.fileInfo_)),
+	  prefix_(std::move(other.prefix_))
 {
-	other.severity_ = LogInvalid;
 }
 
 void LogMessage::init(const char *fileName, unsigned int line)