Browse Source

Merge pull request #567 from DhruvMaroo/string

added String's move constructor and move assignment operator
Marc 4 years ago
parent
commit
fda7ddd158
2 changed files with 11 additions and 0 deletions
  1. 2 0
      include/core/String.hpp
  2. 9 0
      src/core/String.cpp

+ 2 - 0
include/core/String.hpp

@@ -40,6 +40,7 @@ public:
 	String(const wchar_t *contents);
 	String(const wchar_t c);
 	String(const String &other);
+	String(String &&other);
 
 	~String();
 
@@ -55,6 +56,7 @@ public:
 	wchar_t operator[](const int idx) const;
 
 	void operator=(const String &s);
+	void operator=(String &&s);
 	bool operator==(const String &s) const;
 	bool operator!=(const String &s) const;
 	String operator+(const String &s) const;

+ 9 - 0
src/core/String.cpp

@@ -73,6 +73,10 @@ String::String(const String &other) {
 	godot::api->godot_string_new_copy(&_godot_string, &other._godot_string);
 }
 
+String::String(String &&other) {
+	godot::api->godot_string_new_copy(&_godot_string, &other._godot_string);
+}
+
 String::~String() {
 	godot::api->godot_string_destroy(&_godot_string);
 }
@@ -94,6 +98,11 @@ void String::operator=(const String &s) {
 	godot::api->godot_string_new_copy(&_godot_string, &s._godot_string);
 }
 
+void String::operator=(String &&s) {
+	godot::api->godot_string_destroy(&_godot_string);
+	godot::api->godot_string_new_copy(&_godot_string, &s._godot_string);
+}
+
 bool String::operator==(const String &s) const {
 	return godot::api->godot_string_operator_equal(&_godot_string, &s._godot_string);
 }