From 443cb2bea0cae07b57b9acd6ee798aa0d30f596e Mon Sep 17 00:00:00 2001
From: Rye Mutt <rye@alchemyviewer.org>
Date: Sun, 5 Jan 2020 04:00:01 -0500
Subject: [PATCH] Eliminate string copies from LLTextBase getText

---
 indra/llprimitive/llmediaentry.h        |  4 ++--
 indra/llui/llaccordionctrltab.cpp       | 10 +++++-----
 indra/llui/llaccordionctrltab.h         |  2 +-
 indra/llui/llcheckboxctrl.cpp           |  2 +-
 indra/llui/llcheckboxctrl.h             |  2 +-
 indra/llui/llcombobox.cpp               |  2 +-
 indra/llui/lldraghandle.cpp             |  4 ++--
 indra/llui/lldraghandle.h               |  6 +++---
 indra/llui/llfolderviewitem.cpp         |  2 +-
 indra/llui/lltextbase.cpp               |  4 ++--
 indra/llui/lltextbase.h                 |  2 +-
 indra/llui/lltimectrl.cpp               |  2 +-
 indra/newview/llexpandabletextbox.h     |  2 +-
 indra/newview/llfloaterimnearbychat.cpp |  2 +-
 indra/newview/llfloaterimnearbychat.h   |  2 +-
 indra/newview/llvoicevivox.h            |  4 ++--
 16 files changed, 26 insertions(+), 26 deletions(-)

diff --git a/indra/llprimitive/llmediaentry.h b/indra/llprimitive/llmediaentry.h
index 33855b3fb2..c6ace4ffc1 100644
--- a/indra/llprimitive/llmediaentry.h
+++ b/indra/llprimitive/llmediaentry.h
@@ -69,8 +69,8 @@ public:
     // "general" fields
     bool getAltImageEnable() const { return mAltImageEnable; }
     MediaControls getControls() const { return mControls; }
-    std::string getCurrentURL() const { return mCurrentURL; }
-    std::string getHomeURL() const { return mHomeURL; }
+    const std::string& getCurrentURL() const { return mCurrentURL; }
+    const std::string& getHomeURL() const { return mHomeURL; }
     bool getAutoLoop() const { return mAutoLoop; }
     bool getAutoPlay() const { return mAutoPlay; }
     bool getAutoScale() const { return mAutoScale; }
diff --git a/indra/llui/llaccordionctrltab.cpp b/indra/llui/llaccordionctrltab.cpp
index bf63db4924..b251505ca3 100644
--- a/indra/llui/llaccordionctrltab.cpp
+++ b/indra/llui/llaccordionctrltab.cpp
@@ -68,10 +68,10 @@ public:
 
 	BOOL postBuild() override;
 
-	std::string getTitle();
+	const std::string& getTitle();
 	void	setTitle(const std::string& title, const std::string& hl);
 
-	void	setTitleFontStyle(std::string style);
+	void	setTitleFontStyle(const std::string& style);
 
 	void	setTitleColor(const LLUIColor& color);
 
@@ -155,7 +155,7 @@ BOOL LLAccordionCtrlTab::LLAccordionCtrlTabHeader::postBuild()
 	return TRUE;
 }
 
-std::string LLAccordionCtrlTab::LLAccordionCtrlTabHeader::getTitle()
+const std::string& LLAccordionCtrlTab::LLAccordionCtrlTabHeader::getTitle()
 {
 	if(mHeaderTextbox)
 	{
@@ -179,7 +179,7 @@ void LLAccordionCtrlTab::LLAccordionCtrlTabHeader::setTitle(const std::string& t
 	}
 }
 
-void LLAccordionCtrlTab::LLAccordionCtrlTabHeader::setTitleFontStyle(std::string style)
+void LLAccordionCtrlTab::LLAccordionCtrlTabHeader::setTitleFontStyle(const std::string& style)
 {
 	if (mHeaderTextbox)
 	{
@@ -508,7 +508,7 @@ void LLAccordionCtrlTab::setAccordionView(LLView* panel)
 	addChild(panel,0);
 }
 
-std::string LLAccordionCtrlTab::getTitle() const
+const std::string& LLAccordionCtrlTab::getTitle() const
 {
 	if (mHeader)
 	{
diff --git a/indra/llui/llaccordionctrltab.h b/indra/llui/llaccordionctrltab.h
index cf828a19ef..551a12c258 100644
--- a/indra/llui/llaccordionctrltab.h
+++ b/indra/llui/llaccordionctrltab.h
@@ -109,7 +109,7 @@ public:
 	void		setAccordionView(LLView* panel);
 	LLView*		getAccordionView() { return mContainerPanel; };
 
-	std::string getTitle() const;
+	const std::string& getTitle() const;
 
 	// Set text and highlight substring in LLAccordionCtrlTabHeader
 	void setTitle(const std::string& title, const std::string& hl = LLStringUtil::null);
diff --git a/indra/llui/llcheckboxctrl.cpp b/indra/llui/llcheckboxctrl.cpp
index 4f312bc9ee..d1d331515f 100644
--- a/indra/llui/llcheckboxctrl.cpp
+++ b/indra/llui/llcheckboxctrl.cpp
@@ -191,7 +191,7 @@ void LLCheckBoxCtrl::setLabel( const LLStringExplicit& label )
 	reshape(getRect().getWidth(), getRect().getHeight(), FALSE);
 }
 
-std::string LLCheckBoxCtrl::getLabel() const
+const std::string& LLCheckBoxCtrl::getLabel() const
 {
 	return mLabel->getText();
 }
diff --git a/indra/llui/llcheckboxctrl.h b/indra/llui/llcheckboxctrl.h
index 03f994268c..97045e886f 100644
--- a/indra/llui/llcheckboxctrl.h
+++ b/indra/llui/llcheckboxctrl.h
@@ -99,7 +99,7 @@ public:
 	void				setDisabledColor( const LLColor4 &color ) { mTextDisabledColor = color; }
 
 	void				setLabel( const LLStringExplicit& label );
-	std::string			getLabel() const;
+	const std::string&	getLabel() const;
 
 	void				setFont( const LLFontGL* font ) { mFont = font; }
 	const LLFontGL*		getFont() { return mFont; }
diff --git a/indra/llui/llcombobox.cpp b/indra/llui/llcombobox.cpp
index 3a34a34cac..58686e2a55 100644
--- a/indra/llui/llcombobox.cpp
+++ b/indra/llui/llcombobox.cpp
@@ -1011,7 +1011,7 @@ void LLComboBox::updateSelection()
 
 void LLComboBox::onTextCommit(const LLSD& data)
 {
-	std::string text = mTextEntry->getText();
+	const std::string& text = mTextEntry->getText();
 	setSimple(text);
 	onCommit();
 	mTextEntry->selectAll();
diff --git a/indra/llui/lldraghandle.cpp b/indra/llui/lldraghandle.cpp
index 1925c2af6b..08b22f1488 100644
--- a/indra/llui/lldraghandle.cpp
+++ b/indra/llui/lldraghandle.cpp
@@ -115,7 +115,7 @@ void LLDragHandleTop::setTitle(const std::string& title)
 }
 
 
-std::string LLDragHandleTop::getTitle() const
+const std::string& LLDragHandleTop::getTitle() const
 {
 	return mTitleBox == nullptr ? LLStringUtil::null : mTitleBox->getText();
 }
@@ -133,7 +133,7 @@ void LLDragHandleLeft::setTitle(const std::string& )
 }
 
 
-std::string LLDragHandleLeft::getTitle() const
+const std::string& LLDragHandleLeft::getTitle() const
 {
 	return LLStringUtil::null;
 }
diff --git a/indra/llui/lldraghandle.h b/indra/llui/lldraghandle.h
index 14d2da57f5..8467bb0394 100644
--- a/indra/llui/lldraghandle.h
+++ b/indra/llui/lldraghandle.h
@@ -70,7 +70,7 @@ public:
 	void			setTitleVisible(BOOL visible);
 
 	virtual void	setTitle( const std::string& title ) = 0;
-	virtual std::string	getTitle() const = 0;
+	virtual const std::string& getTitle() const = 0;
 
 	BOOL	handleHover(S32 x, S32 y, MASK mask) override;
 	BOOL	handleMouseDown(S32 x, S32 y, MASK mask) override;
@@ -109,7 +109,7 @@ protected:
 	friend class LLUICtrlFactory;
 public:
 	void	setTitle( const std::string& title ) override;
-	std::string getTitle() const override;
+	const std::string& getTitle() const override;
 	void	draw() override;
 	void	reshape(S32 width, S32 height, BOOL called_from_parent = TRUE) override;
 
@@ -127,7 +127,7 @@ protected:
 	friend class LLUICtrlFactory;
 public:
 	void	setTitle( const std::string& title ) override;
-	std::string getTitle() const override;
+	const std::string& getTitle() const override;
 	void	draw() override;
 	void	reshape(S32 width, S32 height, BOOL called_from_parent = TRUE) override;
 
diff --git a/indra/llui/llfolderviewitem.cpp b/indra/llui/llfolderviewitem.cpp
index a1ec741ebb..d28075d15a 100644
--- a/indra/llui/llfolderviewitem.cpp
+++ b/indra/llui/llfolderviewitem.cpp
@@ -492,7 +492,7 @@ void LLFolderViewItem::rename(const std::string& new_name)
 
 const std::string& LLFolderViewItem::getName( void ) const
 {
-	static const std::string noName("");
+	static const std::string noName;
 	return getViewModelItem() ? getViewModelItem()->getName() : noName;
 }
 
diff --git a/indra/llui/lltextbase.cpp b/indra/llui/lltextbase.cpp
index 61ef14cdd6..70469845b8 100644
--- a/indra/llui/lltextbase.cpp
+++ b/indra/llui/lltextbase.cpp
@@ -2047,9 +2047,9 @@ void LLTextBase::setText(const LLStringExplicit &utf8str, const LLStyle::Params&
 }
 
 //virtual
-std::string LLTextBase::getText() const
+const std::string& LLTextBase::getText() const
 {
-	return getViewModel()->getValue().asString();
+	return getViewModel()->getValue().asStringRef();
 }
 
 // IDEVO - icons can be UI image names or UUID sent from
diff --git a/indra/llui/lltextbase.h b/indra/llui/lltextbase.h
index 5433ff4951..cd62612b5b 100644
--- a/indra/llui/lltextbase.h
+++ b/indra/llui/lltextbase.h
@@ -396,7 +396,7 @@ public:
 	// Text accessors
 	// TODO: add optional style parameter
 	virtual void			setText(const LLStringExplicit &utf8str , const LLStyle::Params& input_params = LLStyle::Params()); // uses default style
-	virtual std::string		getText() const;
+	virtual const std::string& getText() const;
 	void					setMaxTextLength(S32 length) { mMaxTextByteLength = length; }
 
 	// wide-char versions
diff --git a/indra/llui/lltimectrl.cpp b/indra/llui/lltimectrl.cpp
index ef673506ad..e26d423962 100644
--- a/indra/llui/lltimectrl.cpp
+++ b/indra/llui/lltimectrl.cpp
@@ -320,7 +320,7 @@ void LLTimeCtrl::updateText()
 LLTimeCtrl::EEditingPart LLTimeCtrl::getEditingPart()
 {
 	S32 cur_pos = mEditor->getCursor();
-	std::string time_str = mEditor->getText();
+	const std::string& time_str = mEditor->getText();
 
 	size_t colon_index = time_str.find_first_of(':');
 
diff --git a/indra/newview/llexpandabletextbox.h b/indra/newview/llexpandabletextbox.h
index 8a976e9c29..8452ca074d 100644
--- a/indra/newview/llexpandabletextbox.h
+++ b/indra/newview/llexpandabletextbox.h
@@ -121,7 +121,7 @@ public:
 	/**
 	 * Returns text
 	 */
-	virtual std::string getText() const { return mText; }
+	virtual const std::string& getText() const { return mText; }
 
 	/**
 	 * Sets text
diff --git a/indra/newview/llfloaterimnearbychat.cpp b/indra/newview/llfloaterimnearbychat.cpp
index 05015162c0..1c4b4fe2af 100644
--- a/indra/newview/llfloaterimnearbychat.cpp
+++ b/indra/newview/llfloaterimnearbychat.cpp
@@ -373,7 +373,7 @@ void LLFloaterIMNearbyChat::showHistory()
 	setResizeLimits(getMinWidth(), EXPANDED_MIN_HEIGHT);
 }
 
-std::string LLFloaterIMNearbyChat::getCurrentChat() const
+const std::string& LLFloaterIMNearbyChat::getCurrentChat() const
 {
 	return mInputEditor ? mInputEditor->getText() : LLStringUtil::null;
 }
diff --git a/indra/newview/llfloaterimnearbychat.h b/indra/newview/llfloaterimnearbychat.h
index 244d04f000..826dd891ee 100644
--- a/indra/newview/llfloaterimnearbychat.h
+++ b/indra/newview/llfloaterimnearbychat.h
@@ -63,7 +63,7 @@ public:
 
 	LLChatEntry* getChatBox() const { return mInputEditor; }
 
-	std::string getCurrentChat() const;
+	const std::string& getCurrentChat() const;
 	S32 getMessageArchiveLength() const {return mMessageArchive.size();}
 
 	BOOL handleKeyHere( KEY key, MASK mask ) override;
diff --git a/indra/newview/llvoicevivox.h b/indra/newview/llvoicevivox.h
index 7764b58a30..0a8dbcc069 100644
--- a/indra/newview/llvoicevivox.h
+++ b/indra/newview/llvoicevivox.h
@@ -1025,8 +1025,8 @@ class LLVivoxSecurity final :	public LLSingleton<LLVivoxSecurity>
     virtual ~LLVivoxSecurity();
 
   public:
-    std::string     connectorHandle() { return mConnectorHandle; };
-    std::string     accountHandle()    { return mAccountHandle;    };
+    const std::string&     connectorHandle() { return mConnectorHandle; };
+    const std::string&     accountHandle()    { return mAccountHandle;    };
 
 #ifdef LL_LINUX
     void setConnectorHandle(const std::string& handle) { mConnectorHandle = handle; }
-- 
GitLab