From 3f2af66e0becce812d9b688808124acf7117b11d Mon Sep 17 00:00:00 2001
From: Rye Mutt <rye@alchemyviewer.org>
Date: Tue, 6 Oct 2020 03:37:47 -0400
Subject: [PATCH] Continue the never ending war on string temporaries

---
 indra/llcommon/llstring.cpp                 | 12 +++++----
 indra/llmessage/llavatarname.cpp            | 21 +++++++--------
 indra/llmessage/llcachename.cpp             |  4 +--
 indra/llmessage/llexperiencecache.cpp       |  8 +++---
 indra/llmessage/llhttpnode.cpp              |  2 +-
 indra/llmessage/lltrustedmessageservice.cpp |  2 +-
 indra/llui/llfloater.cpp                    |  2 +-
 indra/llui/llnotifications.cpp              | 29 ++++++++++-----------
 indra/newview/llmeshrepository.cpp          |  3 +--
 indra/newview/llviewerchat.cpp              |  5 ++--
 indra/newview/rlvinventory.cpp              |  2 +-
 11 files changed, 44 insertions(+), 46 deletions(-)

diff --git a/indra/llcommon/llstring.cpp b/indra/llcommon/llstring.cpp
index 686aa0a1b1b..a2c69d1f041 100644
--- a/indra/llcommon/llstring.cpp
+++ b/indra/llcommon/llstring.cpp
@@ -1225,7 +1225,7 @@ bool LLStringUtil::simpleReplacement(std::string &replacement, std::string token
 		return true;
 	}
 	// if not, see if there's one WITH brackets
-	iter = substitutions.find(std::string("[" + token + "]"));
+	iter = substitutions.find(absl::StrCat("[", token, "]"));
 	if (iter != substitutions.end())
 	{
 		replacement = iter->second;
@@ -1248,10 +1248,12 @@ bool LLStringUtil::simpleReplacement(std::string &replacement, std::string token
 		replacement = substitutions[token].asString();
 		return true;
 	}
+
 	// if not, see if there's one WITH brackets
-	else if (substitutions.has(std::string("[" + token + "]")))
+	std::string temp_token = absl::StrCat("[", token, "]");
+	if (substitutions.has(temp_token))
 	{
-		replacement = substitutions[std::string("[" + token + "]")].asString();
+		replacement = substitutions[temp_token].asString();
 		return true;
 	}
 
@@ -1493,7 +1495,7 @@ S32 LLStringUtil::format(std::string& s, const format_map_t& substitutions)
 	}
 	// send the remainder of the string (with no further matches for bracketed names)
 	output += std::string(s, start);
-	s = output;
+	s = std::move(output);
 	return res;
 }
 
@@ -1563,7 +1565,7 @@ S32 LLStringUtil::format(std::string& s, const LLSD& substitutions)
 	}
 	// send the remainder of the string (with no further matches for bracketed names)
 	output += std::string(s, start);
-	s = output;
+	s = std::move(output);
 	return res;
 }
 
diff --git a/indra/llmessage/llavatarname.cpp b/indra/llmessage/llavatarname.cpp
index 3e1545b7170..a992fd66689 100644
--- a/indra/llmessage/llavatarname.cpp
+++ b/indra/llmessage/llavatarname.cpp
@@ -137,7 +137,7 @@ void LLAvatarName::fromString(const std::string& full_name)
 		mLegacyLastName = full_name.substr(index+1);
 		if (mLegacyLastName != "Resident")
 		{
-			mUsername = mLegacyFirstName + "." + mLegacyLastName;
+			mUsername = absl::StrCat(mLegacyFirstName, ".", mLegacyLastName);
 			mDisplayName = full_name;
 			LLStringUtil::toLower(mUsername);
 		}
@@ -179,18 +179,21 @@ std::string LLAvatarName::getCompleteName(bool use_parentheses, bool force_use_c
 		}
 		else
 		{
-			name = mDisplayName;
 			if(sUseUsernames || force_use_complete_name)
 			{
 				if(use_parentheses)
 				{
-				    name += " (" + mUsername + ")";
+				    name = absl::StrCat(mDisplayName, " (", mUsername, ")");
 				}
 				else
 				{
-				    name += "  [ " + mUsername + " ]";
+				    name = absl::StrCat(mDisplayName, "  [ ", mUsername, " ]");
 				}
 			}
+			else
+			{
+				name = mDisplayName;
+			}
 		}
 	}
 	else
@@ -207,11 +210,7 @@ std::string LLAvatarName::getLegacyName() const
 		return mDisplayName;
 	}
 
-	std::string name;
-	name.reserve( mLegacyFirstName.size() + 1 + mLegacyLastName.size() );
-	name = mLegacyFirstName;
-	name += " ";
-	name += mLegacyLastName;
+	std::string name = absl::StrCat(mLegacyFirstName, " ", mLegacyLastName);
 	return name;
 }
 
@@ -247,12 +246,12 @@ std::string LLAvatarName::getUserName(bool lowercase) const
 	{
 		if(lowercase)
 		{
-		    name = mLegacyFirstName + "." + mLegacyLastName;
+		    name = absl::StrCat(mLegacyFirstName, ".", mLegacyLastName);
 		    LLStringUtil::toLower(name);
 		}
 		else
 		{
-		    name = mLegacyFirstName + " " + mLegacyLastName;
+		    name = absl::StrCat(mLegacyFirstName, " ", mLegacyLastName);
 	    }
 	}
 	return name;
diff --git a/indra/llmessage/llcachename.cpp b/indra/llmessage/llcachename.cpp
index 47762946292..dc72ddd2246 100644
--- a/indra/llmessage/llcachename.cpp
+++ b/indra/llmessage/llcachename.cpp
@@ -543,7 +543,7 @@ std::string LLCacheName::buildUsername(const std::string& full_name)
 
 		if (lastname != "Resident")
 		{
-			username = username + "." + lastname;
+			username = absl::StrCat(username, ".", lastname);
 		}
 		
 		LLStringUtil::toLower(username);
@@ -586,7 +586,7 @@ std::string LLCacheName::buildLegacyName(const std::string& complete_name)
 				{
 					cap_letter = last_name.substr(0, 1);
 					LLStringUtil::toUpper(cap_letter);
-					legacy_name = legacy_name + " " + cap_letter + last_name.substr(1);
+					legacy_name = absl::StrCat(legacy_name, " ", cap_letter, last_name.substr(1));
 				}
 			}
 
diff --git a/indra/llmessage/llexperiencecache.cpp b/indra/llmessage/llexperiencecache.cpp
index 76e2e26560c..87474bfee85 100644
--- a/indra/llmessage/llexperiencecache.cpp
+++ b/indra/llmessage/llexperiencecache.cpp
@@ -672,7 +672,7 @@ void LLExperienceCache::getGroupExperiencesCoro(LLCoreHttpUtil::HttpCoroutineAda
         return;
     }
 
-    url += "?" + groupId.asString();
+    absl::StrAppend(&url, "?", groupId.asString());
 
     LLSD result = httpAdapter->getAndSuspend(httpRequest, url);
 
@@ -744,7 +744,7 @@ void LLExperienceCache::getExperiencePermission(const LLUUID &experienceId, Expe
         return;
     }
 
-    std::string url = mCapability("ExperiencePreferences") + "?" + experienceId.asString();
+    std::string url = absl::StrCat(mCapability("ExperiencePreferences"), "?", experienceId.asString());
     
     permissionInvoker_fn invoker(boost::bind(
         // Humans ignore next line.  It is just a cast to specify which LLCoreHttpUtil::HttpCoroutineAdapter routine overload.
@@ -798,7 +798,7 @@ void LLExperienceCache::forgetExperiencePermission(const LLUUID &experienceId, E
         return;
     }
 
-    std::string url = mCapability("ExperiencePreferences") + "?" + experienceId.asString();
+    std::string url = absl::StrCat(mCapability("ExperiencePreferences"), "?", experienceId.asString());
 
 
     permissionInvoker_fn invoker(boost::bind(
@@ -856,7 +856,7 @@ void LLExperienceCache::getExperienceAdminCoro(LLCoreHttpUtil::HttpCoroutineAdap
         LL_WARNS("ExperienceCache") << "No Region Experiences capability" << LL_ENDL;
         return;
     }
-    url += "?experience_id=" + experienceId.asString();
+    absl::StrAppend(&url, "?experience_id=", experienceId.asString());
 
     LLSD result = httpAdapter->getAndSuspend(httpRequest, url);
 //     LLSD httpResults = result[LLCoreHttpUtil::HttpCoroutineAdapter::HTTP_RESULTS];
diff --git a/indra/llmessage/llhttpnode.cpp b/indra/llmessage/llhttpnode.cpp
index 8b8dfde030d..dff1020bd9f 100644
--- a/indra/llmessage/llhttpnode.cpp
+++ b/indra/llmessage/llhttpnode.cpp
@@ -343,7 +343,7 @@ static void append_node_paths(LLSD& result,
 	
 	for (; i != end; ++i)
 	{
-		result.append(name + "/" + (*i).asString());
+		result.append(absl::StrCat(name, "/", (*i).asString()));
 	}
 }
 
diff --git a/indra/llmessage/lltrustedmessageservice.cpp b/indra/llmessage/lltrustedmessageservice.cpp
index 33944f78830..5afd17a1f94 100644
--- a/indra/llmessage/lltrustedmessageservice.cpp
+++ b/indra/llmessage/lltrustedmessageservice.cpp
@@ -49,7 +49,7 @@ void LLTrustedMessageService::post(LLHTTPNode::ResponsePtr response,
 		["x-secondlife-udp-listen-port"];
 
 	LLSD message_data;
-	std::string sender = senderIP + ":" + senderPort;
+	std::string sender = absl::StrCat(senderIP, ":", senderPort);
 	message_data["sender"] = sender;
 	message_data["body"] = input;
 	
diff --git a/indra/llui/llfloater.cpp b/indra/llui/llfloater.cpp
index c336966f229..17421969a42 100644
--- a/indra/llui/llfloater.cpp
+++ b/indra/llui/llfloater.cpp
@@ -581,7 +581,7 @@ std::string LLFloater::getControlName(const std::string& name, const LLSD& key)
 	// Add the key to the control name if appropriate.
 	if (key.isString() && !key.asString().empty())
 	{
-		ctrl_name += "_" + key.asString();
+		absl::StrAppend(&ctrl_name, "_", key.asString());
 	}
 
 	return ctrl_name;
diff --git a/indra/llui/llnotifications.cpp b/indra/llui/llnotifications.cpp
index ac112281fd2..7db7b381d11 100644
--- a/indra/llui/llnotifications.cpp
+++ b/indra/llui/llnotifications.cpp
@@ -650,7 +650,7 @@ std::string LLNotification::getSelectedOptionName(const LLSD& response)
 			return llsd_pair.first;
 		}
 	}
-	return "";
+	return std::string();
 }
 
 
@@ -681,7 +681,7 @@ void LLNotification::respond(const LLSD& response)
 	if (mTemporaryResponder)
 	{
 		LLNotificationFunctorRegistry::instance().unregisterFunctor(mResponseFunctorName);
-		mResponseFunctorName = "";
+		mResponseFunctorName.clear();
 		mTemporaryResponder = false;
 	}
 
@@ -690,7 +690,7 @@ void LLNotification::respond(const LLSD& response)
 		mForm->setIgnored(mIgnored);
 		if (mIgnored && mForm->getIgnoreType() == LLNotificationForm::IGNORE_WITH_LAST_RESPONSE)
 		{
-			LLUI::getInstance()->mSettingGroups["ignores"]->setLLSD("Default" + getName(), response);
+			LLUI::getInstance()->mSettingGroups["ignores"]->setLLSD(absl::StrCat("Default", getName()), response);
 		}
 	}
 
@@ -729,7 +729,7 @@ bool LLNotification::isPersistent() const
 
 std::string LLNotification::getType() const
 {
-	return (mTemplatep ? mTemplatep->mType : "");
+	return (mTemplatep ? mTemplatep->mType : std::string());
 }
 
 S32 LLNotification::getURLOption() const
@@ -873,10 +873,7 @@ void LLNotification::init(const std::string& template_name, const LLSD& form_ele
 
 std::string LLNotification::summarize() const
 {
-	std::string s = "Notification(";
-	s += getName();
-	s += ") : ";
-	s += mTemplatep ? mTemplatep->mMessage : "";
+	std::string s = absl::StrCat("Notification(", getName(), ") : ", mTemplatep ? mTemplatep->mMessage : "");
 	// should also include timestamp and expiration time (but probably not payload)
 	return s;
 }
@@ -906,14 +903,19 @@ std::string LLNotification::getFooter() const
 
 std::string LLNotification::getLabel() const
 {
+	if (!mTemplatep)
+		return std::string();
+
 	std::string label = mTemplatep->mLabel;
 	LLStringUtil::format(label, mSubstitutions);
-	return (mTemplatep ? label : "");
+	return label;
 }
 
 // [SL:KB] - Patch: UI-Notifications | Checked: 2011-04-11 (Catznip-2.5.0a) | Added: Catznip-2.5.0a
 bool LLNotification::hasLabel() const
 {
+	if (!mTemplatep)
+		return false;
 	return !mTemplatep->mLabel.empty();
 }
 // [/SL:KB]
@@ -924,7 +926,7 @@ std::string LLNotification::getURL() const
 		return std::string();
 	std::string url = mTemplatep->mURL;
 	LLStringUtil::format(url, mSubstitutions);
-	return (mTemplatep ? url : "");
+	return url;
 }
 
 bool LLNotification::canLogToChat() const
@@ -1188,13 +1190,10 @@ size_t LLNotificationChannel::size()
 
 std::string LLNotificationChannel::summarize()
 {
-	std::string s("Channel '");
-	s += mName;
-	s += "'\n  ";
+	std::string s = absl::StrCat("Channel '", mName, "'\n  ");
 	for (LLNotificationChannel::Iterator it = begin(); it != end(); ++it)
 	{
-		s += (*it)->summarize();
-		s += "\n  ";
+		absl::StrAppend(&s, (*it)->summarize(), "\n  ");
 	}
 	return s;
 }
diff --git a/indra/newview/llmeshrepository.cpp b/indra/newview/llmeshrepository.cpp
index 3c28396be0e..8e4cb5aedb4 100644
--- a/indra/newview/llmeshrepository.cpp
+++ b/indra/newview/llmeshrepository.cpp
@@ -1232,8 +1232,7 @@ void LLMeshRepoThread::constructUrl(LLUUID mesh_id, std::string * url)
 
 		if (!res_url.empty())
 		{
-			res_url += "/?mesh_id=";
-			res_url += mesh_id.asString();
+			absl::StrAppend(&res_url, "/?mesh_id=", mesh_id.asString());
 		}
 		else
 		{
diff --git a/indra/newview/llviewerchat.cpp b/indra/newview/llviewerchat.cpp
index 1c3c547bc15..43752292bbb 100644
--- a/indra/newview/llviewerchat.cpp
+++ b/indra/newview/llviewerchat.cpp
@@ -251,8 +251,7 @@ std::string LLViewerChat::getSenderSLURL(const LLChat& chat, const LLSD& args)
 std::string LLViewerChat::getObjectImSLURL(const LLChat& chat, const LLSD& args)
 {
 	std::string url = LLSLURL("objectim", chat.mFromID, "").getSLURLString();
-	url += "?name=" + chat.mFromName;
-	url += "&owner=" + chat.mOwnerID.asString();
+	absl::StrAppend(&url, "?name=", chat.mFromName, "&owner=", chat.mOwnerID.asString());
 
 	std::string slurl = args["slurl"].asString();
 	if (slurl.empty())
@@ -265,7 +264,7 @@ std::string LLViewerChat::getObjectImSLURL(const LLChat& chat, const LLSD& args)
 		}
 	}
 
-	url += "&slurl=" + LLURI::escape(slurl);
+	absl::StrAppend(&url, "&slurl=", LLURI::escape(slurl));
 
 	return url;
 }
diff --git a/indra/newview/rlvinventory.cpp b/indra/newview/rlvinventory.cpp
index c29a7f38636..d5ff0f5dc98 100644
--- a/indra/newview/rlvinventory.cpp
+++ b/indra/newview/rlvinventory.cpp
@@ -452,7 +452,7 @@ void RlvRenameOnWearObserver::doneIdle()
 				std::string strName = pItem->getName();
 				LLStringUtil::truncate(strName, DB_INV_ITEM_NAME_STR_LEN - strAttachPt.length() - 3);
 
-				strName += " (" + strAttachPt + ")";
+				absl::StrAppend(&strName, " (", strAttachPt, ")");
 
 				pItem->rename(strName);
 				pItem->updateServer(FALSE);
-- 
GitLab