summaryrefslogtreecommitdiffstats
path: root/src/core/String.cpp
diff options
context:
space:
mode:
authorDhruvMaroo <dhruvmaru007@gmail.com>2021-05-31 00:52:36 +0530
committerDhruvMaroo <dhruvmaru007@gmail.com>2021-05-31 00:52:36 +0530
commitcd05371ce86cc5a4d4fb66187f4df1edc2f03e16 (patch)
tree0673bfdaea85460d5058e44413ee07e92083359f /src/core/String.cpp
parent492285f681e68e61431380283e7a04f56de4cb08 (diff)
downloadredot-cpp-cd05371ce86cc5a4d4fb66187f4df1edc2f03e16.tar.gz
added class member, safety check in the destructor
Diffstat (limited to 'src/core/String.cpp')
-rw-r--r--src/core/String.cpp13
1 files changed, 8 insertions, 5 deletions
diff --git a/src/core/String.cpp b/src/core/String.cpp
index 767578f..04b7387 100644
--- a/src/core/String.cpp
+++ b/src/core/String.cpp
@@ -74,12 +74,15 @@ String::String(const String &other) {
}
String::String(String&& other) {
- godot::api->godot_string_new_copy(&_godot_string, &other._godot_string);
- godot::api->godot_string_destroy(&_godot_string);
+ _godot_string = other._godot_string;
+ other._deleted = true;
}
String::~String() {
- godot::api->godot_string_destroy(&_godot_string);
+ if (!_deleted) {
+ godot::api->godot_string_destroy(&_godot_string);
+ _deleted = true;
+ }
}
wchar_t &String::operator[](const int idx) {
@@ -101,8 +104,8 @@ void String::operator=(const String &s) {
void String::operator=(String&& s) {
godot::api->godot_string_destroy(&_godot_string);
- godot::api->godot_string_new_copy(&_godot_string, &s._godot_string);
- godot::api->godot_string_destroy(&s._godot_string);
+ _godot_string = s._godot_string;
+ s._deleted = true;
}
bool String::operator==(const String &s) const {