summaryrefslogtreecommitdiff
path: root/indra/llui/lluistring.cpp
diff options
context:
space:
mode:
authorrichard <none@none>2009-12-09 17:17:07 -0800
committerrichard <none@none>2009-12-09 17:17:07 -0800
commit23610472d5e09b66cd05039a9c6cb96664fdbaeb (patch)
tree29df2d98f71b0708bbacabb6bcea61909c9c1c0f /indra/llui/lluistring.cpp
parent7466aa198a7707f2acadacfb6709bed8351fff96 (diff)
lazy evaluation of lluistring to improve LLUIString::format performance
reviewed by Mani
Diffstat (limited to 'indra/llui/lluistring.cpp')
-rw-r--r--indra/llui/lluistring.cpp51
1 files changed, 33 insertions, 18 deletions
diff --git a/indra/llui/lluistring.cpp b/indra/llui/lluistring.cpp
index 3a1e656364..f7a53e87de 100644
--- a/indra/llui/lluistring.cpp
+++ b/indra/llui/lluistring.cpp
@@ -39,22 +39,23 @@ LLFastTimer::DeclareTimer FTM_UI_STRING("UI String");
LLUIString::LLUIString(const std::string& instring, const LLStringUtil::format_map_t& args)
- : mOrig(instring),
- mArgs(args)
+: mOrig(instring),
+ mArgs(args)
{
- format();
+ dirty();
}
void LLUIString::assign(const std::string& s)
{
mOrig = s;
- format();
+ dirty();
}
void LLUIString::setArgList(const LLStringUtil::format_map_t& args)
+
{
mArgs = args;
- format();
+ dirty();
}
void LLUIString::setArgs(const LLSD& sd)
@@ -68,40 +69,40 @@ void LLUIString::setArgs(const LLSD& sd)
{
setArg(sd_it->first, sd_it->second.asString());
}
- format();
+ dirty();
}
void LLUIString::setArg(const std::string& key, const std::string& replacement)
{
mArgs[key] = replacement;
- format();
+ dirty();
}
void LLUIString::truncate(S32 maxchars)
{
- if (mWResult.size() > (size_t)maxchars)
+ if (getUpdatedWResult().size() > (size_t)maxchars)
{
- LLWStringUtil::truncate(mWResult, maxchars);
- mResult = wstring_to_utf8str(mWResult);
+ LLWStringUtil::truncate(getUpdatedWResult(), maxchars);
+ mResult = wstring_to_utf8str(getUpdatedWResult());
}
}
void LLUIString::erase(S32 charidx, S32 len)
{
- mWResult.erase(charidx, len);
- mResult = wstring_to_utf8str(mWResult);
+ getUpdatedWResult().erase(charidx, len);
+ mResult = wstring_to_utf8str(getUpdatedWResult());
}
void LLUIString::insert(S32 charidx, const LLWString& wchars)
{
- mWResult.insert(charidx, wchars);
- mResult = wstring_to_utf8str(mWResult);
+ getUpdatedWResult().insert(charidx, wchars);
+ mResult = wstring_to_utf8str(getUpdatedWResult());
}
void LLUIString::replace(S32 charidx, llwchar wc)
{
- mWResult[charidx] = wc;
- mResult = wstring_to_utf8str(mWResult);
+ getUpdatedWResult()[charidx] = wc;
+ mResult = wstring_to_utf8str(getUpdatedWResult());
}
void LLUIString::clear()
@@ -112,8 +113,16 @@ void LLUIString::clear()
mWResult.clear();
}
-void LLUIString::format()
+void LLUIString::dirty()
{
+ mNeedsResult = true;
+ mNeedsWResult = true;
+}
+
+void LLUIString::updateResult() const
+{
+ mNeedsResult = false;
+
LLFastTimer timer(FTM_UI_STRING);
// optimize for empty strings (don't attempt string replacement)
@@ -129,5 +138,11 @@ void LLUIString::format()
LLStringUtil::format_map_t combined_args = LLTrans::getDefaultArgs();
combined_args.insert(mArgs.begin(), mArgs.end());
LLStringUtil::format(mResult, combined_args);
- mWResult = utf8str_to_wstring(mResult);
+}
+
+void LLUIString::updateWResult() const
+{
+ mNeedsWResult = false;
+
+ mWResult = utf8str_to_wstring(getUpdatedResult());
}