From 3e43572a878704886d60e2543238fc21a3d3789e Mon Sep 17 00:00:00 2001 From: "alexey.lysiuk" Date: Mon, 23 Oct 2017 11:48:04 +0300 Subject: [PATCH] Added move semantics to FString class --- src/zstring.cpp | 15 +++++++++++++++ src/zstring.h | 2 ++ 2 files changed, 17 insertions(+) diff --git a/src/zstring.cpp b/src/zstring.cpp index e9b41a6d7f..f4f57c4f3f 100644 --- a/src/zstring.cpp +++ b/src/zstring.cpp @@ -211,6 +211,21 @@ FString &FString::operator = (const FString &other) } return *this; } + +FString &FString::operator = (FString &&other) +{ + assert (Chars != NULL); + + if (&other != this) + { + Data()->Release(); + Chars = other.Chars; + other.ResetToNull(); + } + + return *this; +} + FString &FString::operator = (const char *copyStr) { if (copyStr != Chars) diff --git a/src/zstring.h b/src/zstring.h index e7ab098dde..b6986361f9 100644 --- a/src/zstring.h +++ b/src/zstring.h @@ -124,6 +124,7 @@ public: // Copy constructors FString (const FString &other) { AttachToOther (other); } + FString (FString &&other) : Chars(other.Chars) { other.ResetToNull(); } FString (const char *copyStr); FString (const char *copyStr, size_t copyLen); FString (char oneChar); @@ -165,6 +166,7 @@ public: const char &operator[] (unsigned long long index) const { return Chars[index]; } FString &operator = (const FString &other); + FString &operator = (FString &&other); FString &operator = (const char *copyStr); FString operator + (const FString &tail) const;