Browse Source

Merge pull request #104182 from Ivorforce/small-little-string-function

Add missing `String + char *` function, to avoid unnecessary right side allocation to `String`.
Thaddeus Crews 5 months ago
parent
commit
bb60b05ca4
2 changed files with 21 additions and 0 deletions
  1. 18 0
      core/string/ustring.cpp
  2. 3 0
      core/string/ustring.h

+ 18 - 0
core/string/ustring.cpp

@@ -365,6 +365,24 @@ String String::operator+(const String &p_str) const {
 	return res;
 }
 
+String String::operator+(const char *p_str) const {
+	String res = *this;
+	res += p_str;
+	return res;
+}
+
+String String::operator+(const wchar_t *p_str) const {
+	String res = *this;
+	res += p_str;
+	return res;
+}
+
+String String::operator+(const char32_t *p_str) const {
+	String res = *this;
+	res += p_str;
+	return res;
+}
+
 String String::operator+(char32_t p_char) const {
 	String res = *this;
 	res += p_char;

+ 3 - 0
core/string/ustring.h

@@ -330,6 +330,9 @@ public:
 	bool operator==(const String &p_str) const;
 	bool operator!=(const String &p_str) const;
 	String operator+(const String &p_str) const;
+	String operator+(const char *p_char) const;
+	String operator+(const wchar_t *p_char) const;
+	String operator+(const char32_t *p_char) const;
 	String operator+(char32_t p_char) const;
 
 	String &operator+=(const String &);