optimized LLUIString construction

master
Richard Nelson 2010-08-04 19:01:44 -07:00
parent 932f248553
commit b3bf2d7933
2 changed files with 19 additions and 9 deletions

View File

@ -40,7 +40,7 @@ LLFastTimer::DeclareTimer FTM_UI_STRING("UI String");
LLUIString::LLUIString(const std::string& instring, const LLStringUtil::format_map_t& args)
: mOrig(instring),
mArgs(args)
mArgs(new LLStringUtil::format_map_t(args))
{
dirty();
}
@ -54,7 +54,7 @@ void LLUIString::assign(const std::string& s)
void LLUIString::setArgList(const LLStringUtil::format_map_t& args)
{
mArgs = args;
getArgs() = args;
dirty();
}
@ -74,7 +74,7 @@ void LLUIString::setArgs(const LLSD& sd)
void LLUIString::setArg(const std::string& key, const std::string& replacement)
{
mArgs[key] = replacement;
getArgs()[key] = replacement;
dirty();
}
@ -135,14 +135,14 @@ void LLUIString::updateResult() const
mResult = mOrig;
// get the defailt args + local args
if (mArgs.empty())
if (!mArgs || mArgs->empty())
{
LLStringUtil::format(mResult, LLTrans::getDefaultArgs());
}
else
{
LLStringUtil::format_map_t combined_args = LLTrans::getDefaultArgs();
combined_args.insert(mArgs.begin(), mArgs.end());
combined_args.insert(mArgs->begin(), mArgs->end());
LLStringUtil::format(mResult, combined_args);
}
}
@ -153,3 +153,12 @@ void LLUIString::updateWResult() const
mWResult = utf8str_to_wstring(getUpdatedResult());
}
LLStringUtil::format_map_t& LLUIString::getArgs()
{
if (!mArgs)
{
mArgs = new LLStringUtil::format_map_t;
}
return *mArgs;
}

View File

@ -64,9 +64,9 @@ class LLUIString
public:
// These methods all perform appropriate argument substitution
// and modify mOrig where appropriate
LLUIString() : mNeedsResult(false), mNeedsWResult(false) {}
LLUIString() : mArgs(NULL), mNeedsResult(false), mNeedsWResult(false) {}
LLUIString(const std::string& instring, const LLStringUtil::format_map_t& args);
LLUIString(const std::string& instring) { assign(instring); }
LLUIString(const std::string& instring) : mArgs(NULL) { assign(instring); }
void assign(const std::string& instring);
LLUIString& operator=(const std::string& s) { assign(s); return *this; }
@ -86,7 +86,7 @@ public:
S32 length() const { return getUpdatedWResult().size(); }
void clear();
void clearArgs() { mArgs.clear(); }
void clearArgs() { if (mArgs) mArgs->clear(); }
// These utility functions are included for text editing.
// They do not affect mOrig and do not perform argument substitution
@ -105,11 +105,12 @@ private:
// do actual work of updating strings (non-inlined)
void updateResult() const;
void updateWResult() const;
LLStringUtil::format_map_t& getArgs();
std::string mOrig;
mutable std::string mResult;
mutable LLWString mWResult; // for displaying
LLStringUtil::format_map_t mArgs;
LLStringUtil::format_map_t* mArgs;
// controls lazy evaluation
mutable bool mNeedsResult;