Browse Source

Fix missing moves and avoid some allocations

Michael Ragazzon 3 years ago
parent
commit
18b9a2a6ed

+ 1 - 1
Include/RmlUi/Core/Animation.h

@@ -61,7 +61,7 @@ struct TransitionList {
 
 
 	TransitionList() {}
 	TransitionList() {}
 	TransitionList(bool none, bool all, Vector<Transition> transitions) :
 	TransitionList(bool none, bool all, Vector<Transition> transitions) :
-		none(none), all(all), transitions(transitions) {}
+		none(none), all(all), transitions(std::move(transitions)) {}
 };
 };
 
 
 inline bool operator==(const Animation& a, const Animation& b) { return a.duration == b.duration && a.tween == b.tween && a.delay == b.delay && a.alternate == b.alternate && a.paused == b.paused && a.num_iterations == b.num_iterations && a.name == b.name; }
 inline bool operator==(const Animation& a, const Animation& b) { return a.duration == b.duration && a.tween == b.tween && a.delay == b.delay && a.alternate == b.alternate && a.paused == b.paused && a.num_iterations == b.num_iterations && a.name == b.name; }

+ 1 - 1
Include/RmlUi/Core/DataTypes.h

@@ -58,7 +58,7 @@ template<typename Object, typename AssignType> using MemberSetterFunc = void(Obj
 using DirtyVariables = SmallUnorderedSet<String>;
 using DirtyVariables = SmallUnorderedSet<String>;
 
 
 struct DataAddressEntry {
 struct DataAddressEntry {
-	DataAddressEntry(String name) : name(name), index(-1) { }
+	DataAddressEntry(String name) : name(std::move(name)), index(-1) { }
 	DataAddressEntry(int index) : index(index) { }
 	DataAddressEntry(int index) : index(index) { }
 	String name;
 	String name;
 	int index;
 	int index;

+ 1 - 1
Include/RmlUi/Core/ElementText.h

@@ -93,7 +93,7 @@ private:
 	// Used to store the position and length of each line we have geometry for.
 	// Used to store the position and length of each line we have geometry for.
 	struct Line
 	struct Line
 	{
 	{
-		Line(const String& text, Vector2f position) : text(text), position(position), width(0) {}
+		Line(String text, Vector2f position) : text(std::move(text)), position(position), width(0) {}
 		String text;
 		String text;
 		Vector2f position;
 		Vector2f position;
 		int width;
 		int width;

+ 2 - 2
Include/RmlUi/Core/StringUtilities.h

@@ -71,9 +71,9 @@ namespace StringUtilities
 	RMLUICORE_API void JoinString(String& string, const StringList& string_list, const char delimiter = ',');
 	RMLUICORE_API void JoinString(String& string, const StringList& string_list, const char delimiter = ',');
 
 
 	/// Converts upper-case characters in string to lower-case.
 	/// Converts upper-case characters in string to lower-case.
-	RMLUICORE_API String ToLower(const String& string);
+	RMLUICORE_API String ToLower(String string);
 	/// Converts lower-case characters in string to upper-case.
 	/// Converts lower-case characters in string to upper-case.
-	RMLUICORE_API String ToUpper(const String& string);
+	RMLUICORE_API String ToUpper(String string);
 
 
 	/// Encode RML characters, eg. '<' to '&lt;'
 	/// Encode RML characters, eg. '<' to '&lt;'
 	RMLUICORE_API String EncodeRml(const String& string);
 	RMLUICORE_API String EncodeRml(const String& string);

+ 1 - 1
Source/Core/BaseXMLParser.cpp

@@ -414,7 +414,7 @@ bool BaseXMLParser::ReadCDATA(const char* tag_terminator)
 				{
 				{
 					size_t slash_pos = tag.find('/');
 					size_t slash_pos = tag.find('/');
 					String tag_name = StringUtilities::StripWhitespace(slash_pos == String::npos ? tag : tag.substr(slash_pos + 1));
 					String tag_name = StringUtilities::StripWhitespace(slash_pos == String::npos ? tag : tag.substr(slash_pos + 1));
-					if (StringUtilities::ToLower(tag_name) == tag_terminator)
+					if (StringUtilities::ToLower(std::move(tag_name)) == tag_terminator)
 					{
 					{
 						data += cdata;
 						data += cdata;
 						return true;
 						return true;

+ 5 - 6
Source/Core/DataExpression.cpp

@@ -139,7 +139,7 @@ public:
 			c = Next();
 			c = Next();
 	}
 	}
 
 
-	void Error(const String message)
+	void Error(const String& message)
 	{
 	{
 		parse_error = true;
 		parse_error = true;
 		Log::Message(Log::LT_WARNING, "Error in data expression at %zu. %s", index, message.c_str());
 		Log::Message(Log::LT_WARNING, "Error in data expression at %zu. %s", index, message.c_str());
@@ -149,7 +149,7 @@ public:
 		const String cursor_string = String(cursor_offset, ' ') + '^';
 		const String cursor_string = String(cursor_offset, ' ') + '^';
 		Log::Message(Log::LT_WARNING, "%s", cursor_string.c_str());
 		Log::Message(Log::LT_WARNING, "%s", cursor_string.c_str());
 	}
 	}
-	void Expected(String expected_symbols) {
+	void Expected(const String& expected_symbols) {
 		const char c = Look();
 		const char c = Look();
 		if (c == '\0')
 		if (c == '\0')
 			Error(CreateString(expected_symbols.size() + 50, "Expected %s but found end of string.", expected_symbols.c_str()));
 			Error(CreateString(expected_symbols.size() + 50, "Expected %s but found end of string.", expected_symbols.c_str()));
@@ -780,10 +780,9 @@ public:
 	DataInterpreter(const Program& program, const AddressList& addresses, DataExpressionInterface expression_interface)
 	DataInterpreter(const Program& program, const AddressList& addresses, DataExpressionInterface expression_interface)
 		: program(program), addresses(addresses), expression_interface(expression_interface) {}
 		: program(program), addresses(addresses), expression_interface(expression_interface) {}
 
 
-	bool Error(String message) const
+	bool Error(const String& message) const
 	{
 	{
-		message = "Error during execution. " + message;
-		Log::Message(Log::LT_WARNING, "%s", message.c_str());
+		Log::Message(Log::LT_WARNING, "Error during execution. %s", message.c_str());
 		RMLUI_ERROR;
 		RMLUI_ERROR;
 		return false;
 		return false;
 	}
 	}
@@ -975,7 +974,7 @@ private:
 };
 };
 
 
 
 
-DataExpression::DataExpression(String expression) : expression(expression)
+DataExpression::DataExpression(String expression) : expression(std::move(expression))
 {}
 {}
 
 
 DataExpression::~DataExpression()
 DataExpression::~DataExpression()

+ 1 - 1
Source/Core/DataTypeRegister.cpp

@@ -42,7 +42,7 @@ DataTypeRegister::DataTypeRegister()
 		String value;
 		String value;
 		if (!arguments[0].GetInto(value))
 		if (!arguments[0].GetInto(value))
 			return {};
 			return {};
-		return Variant(StringUtilities::ToLower(value));
+		return Variant(StringUtilities::ToLower(std::move(value)));
 	});
 	});
 
 
 	transform_register.Register("to_upper", [](const VariantList& arguments) -> Variant {
 	transform_register.Register("to_upper", [](const VariantList& arguments) -> Variant {

+ 7 - 1
Source/Core/Element.cpp

@@ -2050,7 +2050,13 @@ void Element::GetRML(String& content)
 		auto& variant = pair.second;
 		auto& variant = pair.second;
 		String value;
 		String value;
 		if (variant.GetInto(value))
 		if (variant.GetInto(value))
-			content += " " + name + "=\"" + value + "\"";
+		{
+			content += ' ';
+			content += name;
+			content += "=\"";
+			content += value;
+			content += "\"";
+		}
 	}
 	}
 
 
 	if (HasChildNodes())
 	if (HasChildNodes())

+ 1 - 1
Source/Core/Elements/ElementFormControlDataSelect.cpp

@@ -175,7 +175,7 @@ void ElementFormControlDataSelect::BuildOptions()
 
 
 	if (valuefield_attribute.empty())
 	if (valuefield_attribute.empty())
 	{
 	{
-		valuefield_attribute = fields_attribute.substr(0, fields_attribute.find(","));
+		valuefield_attribute = fields_attribute.substr(0, fields_attribute.find(','));
 	}
 	}
 
 
 	if (!data_formatter_attribute.empty())
 	if (!data_formatter_attribute.empty())

+ 6 - 8
Source/Core/StringUtilities.cpp

@@ -86,22 +86,20 @@ static inline char CharToLower(char c) {
 	return c;
 	return c;
 }
 }
 
 
-String StringUtilities::ToLower(const String& string) {
-	String str_lower = string;
-	std::transform(str_lower.begin(), str_lower.end(), str_lower.begin(), &CharToLower);
-	return str_lower;
+String StringUtilities::ToLower(String string) {
+	std::transform(string.begin(), string.end(), string.begin(), &CharToLower);
+	return string;
 }
 }
 
 
-String StringUtilities::ToUpper(const String& string)
+String StringUtilities::ToUpper(String string)
 {
 {
-	String str_upper = string;
-	std::transform(str_upper.begin(), str_upper.end(), str_upper.begin(), [](char c) {
+	std::transform(string.begin(), string.end(), string.begin(), [](char c) {
 		if (c >= 'a' && c <= 'z')
 		if (c >= 'a' && c <= 'z')
 			c -= char('a' - 'A');
 			c -= char('a' - 'A');
 		return c;
 		return c;
 		}
 		}
 	);
 	);
-	return str_upper;
+	return string;
 }
 }
 
 
 RMLUICORE_API String StringUtilities::EncodeRml(const String& string)
 RMLUICORE_API String StringUtilities::EncodeRml(const String& string)

+ 3 - 3
Source/Core/StyleSheetParser.cpp

@@ -311,7 +311,7 @@ bool StyleSheetParser::ParseKeyframeBlock(KeyframesMap& keyframes_map, const Str
 	{
 	{
 		float value = 0.0f;
 		float value = 0.0f;
 		int count = 0;
 		int count = 0;
-		rule = StringUtilities::ToLower(rule);
+		rule = StringUtilities::ToLower(std::move(rule));
 		if (rule == "from")
 		if (rule == "from")
 			rule_values.push_back(0.0f);
 			rule_values.push_back(0.0f);
 		else if (rule == "to")
 		else if (rule == "to")
@@ -445,7 +445,7 @@ bool StyleSheetParser::ParseMediaFeatureMap(PropertyDictionary& properties, cons
 				return false;
 				return false;
 			}
 			}
 
 
-			current_string = StringUtilities::StripWhitespace(StringUtilities::ToLower(current_string));
+			current_string = StringUtilities::StripWhitespace(StringUtilities::ToLower(std::move(current_string)));
 
 
 			if (current_string != "and")
 			if (current_string != "and")
 			{
 			{
@@ -482,7 +482,7 @@ bool StyleSheetParser::ParseMediaFeatureMap(PropertyDictionary& properties, cons
 				return false;
 				return false;
 			}
 			}
 
 
-			current_string = StringUtilities::StripWhitespace(StringUtilities::ToLower(current_string));
+			current_string = StringUtilities::StripWhitespace(StringUtilities::ToLower(std::move(current_string)));
 
 
 			if (!IsValidIdentifier(current_string))
 			if (!IsValidIdentifier(current_string))
 			{
 			{

+ 3 - 1
Source/Core/TransformUtilities.cpp

@@ -701,7 +701,9 @@ bool TransformUtilities::InterpolateWith(TransformPrimitive& target, const Trans
 
 
 
 
 template<size_t N>
 template<size_t N>
-static inline String ToString(const Transforms::ResolvedPrimitive<N>& p, String unit, bool rad_to_deg = false, bool only_unit_on_last_value = false) noexcept {
+static String ToString(const Transforms::ResolvedPrimitive<N>& p, const String& unit, bool rad_to_deg = false,
+	bool only_unit_on_last_value = false) noexcept
+{
 	float multiplier = 1.0f;
 	float multiplier = 1.0f;
 	String tmp;
 	String tmp;
 	String result = "(";
 	String result = "(";