Codechange: use std::string without const as return

Otherwise some compilers, e.g. MSVC, do not pick up that these are temporaries
and as such it will pass the temporaries to `const std::string &` instead of
the wanted `std::string &&`
This commit is contained in:
Rubidium 2023-07-03 16:22:15 +02:00 committed by rubidium42
parent b2edf82b69
commit 78f5d58dc6
5 changed files with 15 additions and 15 deletions

View File

@ -48,7 +48,7 @@
EnforceDeityMode(GOAL_INVALID);
EnforcePrecondition(GOAL_INVALID, goal != nullptr);
const std::string &text = goal->GetEncodedText();
std::string text = goal->GetEncodedText();
EnforcePreconditionEncodedText(GOAL_INVALID, text);
EnforcePrecondition(GOAL_INVALID, company == ScriptCompany::COMPANY_INVALID || ScriptCompany::ResolveCompanyID(company) != ScriptCompany::COMPANY_INVALID);
EnforcePrecondition(GOAL_INVALID, IsValidGoalDestination(company, type, destination));
@ -84,7 +84,7 @@
EnforcePrecondition(false, IsValidGoal(goal_id));
EnforceDeityMode(false);
EnforcePrecondition(false, goal != nullptr);
const std::string &text = goal->GetEncodedText();
std::string text = goal->GetEncodedText();
EnforcePreconditionEncodedText(false, text);
return ScriptObject::Command<CMD_SET_GOAL_TEXT>::Do(goal_id, text);
@ -123,7 +123,7 @@
EnforceDeityMode(false);
EnforcePrecondition(false, question != nullptr);
const std::string &text = question->GetEncodedText();
std::string text = question->GetEncodedText();
EnforcePreconditionEncodedText(false, text);
uint min_buttons = (type == QT_QUESTION ? 1 : 0);
EnforcePrecondition(false, CountBits(buttons) >= min_buttons && CountBits(buttons) <= 3);

View File

@ -32,11 +32,11 @@
EnforceDeityMode(LEAGUE_TABLE_INVALID);
EnforcePrecondition(LEAGUE_TABLE_INVALID, title != nullptr);
const std::string &encoded_title = title->GetEncodedText();
std::string encoded_title = title->GetEncodedText();
EnforcePreconditionEncodedText(LEAGUE_TABLE_INVALID, encoded_title);
const std::string &encoded_header = (header != nullptr ? header->GetEncodedText() : std::string{});
const std::string &encoded_footer = (footer != nullptr ? footer->GetEncodedText() : std::string{});
std::string encoded_header = (header != nullptr ? header->GetEncodedText() : std::string{});
std::string encoded_footer = (footer != nullptr ? footer->GetEncodedText() : std::string{});
if (!ScriptObject::Command<CMD_CREATE_LEAGUE_TABLE>::Do(&ScriptInstance::DoCommandReturnLeagueTableID, encoded_title, encoded_header, encoded_footer)) return LEAGUE_TABLE_INVALID;
@ -63,11 +63,11 @@
if (company == ScriptCompany::COMPANY_INVALID) c = INVALID_COMPANY;
EnforcePrecondition(LEAGUE_TABLE_ELEMENT_INVALID, text != nullptr);
const std::string &encoded_text = text->GetEncodedText();
std::string encoded_text = text->GetEncodedText();
EnforcePreconditionEncodedText(LEAGUE_TABLE_ELEMENT_INVALID, encoded_text);
EnforcePrecondition(LEAGUE_TABLE_ELEMENT_INVALID, score != nullptr);
const std::string &encoded_score = score->GetEncodedText();
std::string encoded_score = score->GetEncodedText();
EnforcePreconditionEncodedText(LEAGUE_TABLE_ELEMENT_INVALID, encoded_score);
EnforcePrecondition(LEAGUE_TABLE_ELEMENT_INVALID, IsValidLink(Link((::LinkType)link_type, link_target)));
@ -90,7 +90,7 @@
if (company == ScriptCompany::COMPANY_INVALID) c = INVALID_COMPANY;
EnforcePrecondition(false, text != nullptr);
const std::string &encoded_text = text->GetEncodedText();
std::string encoded_text = text->GetEncodedText();
EnforcePreconditionEncodedText(false, encoded_text);
EnforcePrecondition(false, IsValidLink(Link((::LinkType)link_type, link_target)));
@ -106,7 +106,7 @@
EnforcePrecondition(false, IsValidLeagueTableElement(element));
EnforcePrecondition(false, score != nullptr);
const std::string &encoded_score = score->GetEncodedText();
std::string encoded_score = score->GetEncodedText();
EnforcePreconditionEncodedText(false, encoded_score);
return ScriptObject::Command<CMD_UPDATE_LEAGUE_TABLE_ELEMENT_SCORE>::Do(element, rating, encoded_score);

View File

@ -26,7 +26,7 @@
EnforceDeityMode(false);
EnforcePrecondition(false, text != nullptr);
const std::string &encoded = text->GetEncodedText();
std::string encoded = text->GetEncodedText();
EnforcePreconditionEncodedText(false, encoded);
EnforcePrecondition(false, type == NT_ECONOMY || type == NT_SUBSIDIES || type == NT_GENERAL);
EnforcePrecondition(false, company == ScriptCompany::COMPANY_INVALID || ScriptCompany::ResolveCompanyID(company) != ScriptCompany::COMPANY_INVALID);

View File

@ -158,7 +158,7 @@ SQInteger ScriptText::_set(HSQUIRRELVM vm)
return this->_SetParam(k, vm);
}
const std::string ScriptText::GetEncodedText()
std::string ScriptText::GetEncodedText()
{
static StringIDList seen_ids;
int param_count = 0;

View File

@ -26,7 +26,7 @@ public:
* @return A string.
* @api -all
*/
virtual const std::string GetEncodedText() = 0;
virtual std::string GetEncodedText() = 0;
/**
* Convert a #ScriptText into a decoded normal string.
@ -44,7 +44,7 @@ class RawText : public Text {
public:
RawText(const std::string &text);
const std::string GetEncodedText() override { return this->text; }
std::string GetEncodedText() override { return this->text; }
private:
const std::string text;
};
@ -125,7 +125,7 @@ public:
/**
* @api -all
*/
virtual const std::string GetEncodedText();
virtual std::string GetEncodedText();
private:
using ScriptTextRef = ScriptObjectRef<ScriptText>;