diff --git a/indra/llui/lluicolortable.cpp b/indra/llui/lluicolortable.cpp index cbae44e6a6..bfc70f9628 100644 --- a/indra/llui/lluicolortable.cpp +++ b/indra/llui/lluicolortable.cpp @@ -131,7 +131,14 @@ void LLUIColorTable::insertFromParams(const Params& p, string_color_map_t& table { // since this reference does not refer to another reference it must refer to an // actual color, lets find it... - string_color_map_t::iterator color_value = mLoadedColors.find(previous->second); + + // string_color_map_t::iterator color_value = mLoadedColors.find(previous->second); + + ColorName oName; + oName.nLen = previous->second.size(); + oName.pName = const_cast(previous->second.c_str()); // That's ok, I won't hurt you. + + string_color_map_t::iterator color_value = mLoadedColors.find(oName); if(color_value != mLoadedColors.end()) { @@ -178,14 +185,33 @@ void LLUIColorTable::clear() LLUIColor LLUIColorTable::getColor(const std::string& name, const LLColor4& default_color) const { - string_color_map_t::const_iterator iter = mUserSetColors.find(name); + return getColor( name.c_str(), default_color ); +} + +LLUIColor LLUIColorTable::getColor( char const *name, const LLColor4& default_color) const // Change from std::string to char*, avoind lots of unecessary string constructions +{ + // Change from std::string to char*, avoind lots of unecessary string constructions + + // string_color_map_t::const_iterator iter = mUserSetColors.find(name); + + ColorName oName; + oName.nLen = strlen( name ); + oName.pName = const_cast(name); + string_color_map_t::const_iterator iter = mUserSetColors.find(oName); + + // if(iter != mUserSetColors.end()) { return LLUIColor(&iter->second); } - iter = mLoadedColors.find(name); + // Change from std::string to char*, avoind lots of unecessary string constructions + + // iter = mLoadedColors.find(name); + iter = mLoadedColors.find(oName); + + // if(iter != mLoadedColors.end()) { @@ -238,7 +264,10 @@ void LLUIColorTable::saveUserSettings() const ++it) { ColorEntryParams color_entry; - color_entry.name = it->first; + + // color_entry.name = it->first; + color_entry.name = it->first.pName; + color_entry.color.value = it->second; params.color_entries.add(color_entry); @@ -272,7 +301,10 @@ void LLUIColorTable::saveUserSettingsPaletteOnly() const ++it) { ColorEntryParams color_entry; - color_entry.name = it->first; + + // color_entry.name = it->first; + color_entry.name = it->first.pName; + color_entry.color.value = it->second; @@ -300,10 +332,21 @@ void LLUIColorTable::saveUserSettingsPaletteOnly() const } } -bool LLUIColorTable::colorExists(const std::string& color_name) const +// bool LLUIColorTable::colorExists(const std::string& color_name) const +bool LLUIColorTable::colorExists( char const *name ) const { - return ((mLoadedColors.find(color_name) != mLoadedColors.end()) - || (mUserSetColors.find(color_name) != mUserSetColors.end())); + // Change from std::string to char*, avoind lots of unecessary string constructions + + // return ((mLoadedColors.find(color_name) != mLoadedColors.end()) + // || (mUserSetColors.find(color_name) != mUserSetColors.end())); + + ColorName oName; + oName.nLen = strlen( name ); + oName.pName = const_cast(name); + return ((mLoadedColors.find(oName) != mLoadedColors.end()) + || (mUserSetColors.find(oName) != mUserSetColors.end())); + + // } void LLUIColorTable::clearTable(string_color_map_t& table) @@ -320,15 +363,27 @@ void LLUIColorTable::clearTable(string_color_map_t& table) // if the color already exists it changes the color void LLUIColorTable::setColor(const std::string& name, const LLColor4& color, string_color_map_t& table) { - string_color_map_t::iterator it = table.lower_bound(name); - if(it != table.end() - && !(table.key_comp()(name, it->first))) + + // Change from std::string to char*, avoind lots of unecessary string constructions + + // string_color_map_t::iterator it = table.lower_bound(name); + + ColorName oName; + oName.nLen = name.size(); + oName.pName = const_cast( name.c_str() ); + string_color_map_t::iterator it = table.find(oName); + + // if(it != table.end() && !(table.key_comp()(name, it->first))) + if(it != table.end() ) + + // { it->second = color; } else { - table.insert(it, string_color_map_t::value_type(name, color)); + oName.pName = strdup( oName.pName ); + table.insert(string_color_map_t::value_type(oName, color)); } } diff --git a/indra/llui/lluicolortable.h b/indra/llui/lluicolortable.h index ffcdf5807f..147dab8a54 100644 --- a/indra/llui/lluicolortable.h +++ b/indra/llui/lluicolortable.h @@ -41,7 +41,29 @@ class LLUIColorTable : public LLSingleton LOG_CLASS(LLUIColorTable); // consider using sorted vector, can be much faster - typedef std::map string_color_map_t; + + // Change from std::string to char*, avoind lots of unecessary string constructions + + // typedef std::map string_color_map_t; + + struct ColorName + { + char *pName; + int nLen; + + bool operator<( ColorName const &aRHS ) const + { + if( nLen == aRHS.nLen ) + return strcmp( pName, aRHS.pName ) < 0; + + return nLen < aRHS.nLen; + } + }; + + typedef std::map string_color_map_t; + + + // public: struct ColorParams : LLInitParam::ChoiceBlock @@ -74,13 +96,24 @@ public: void clear(); // color lookup + LLUIColor getColor(const std::string& name, const LLColor4& default_color = LLColor4::magenta) const; + // Change from std::string to char*, avoind lots of unecessary string constructions + LLUIColor getColor(char const *name, const LLColor4& default_color = LLColor4::magenta) const; + // + // if the color is in the table, it's value is changed, otherwise it is added void setColor(const std::string& name, const LLColor4& color); // returns true if color_name exists in the table - bool colorExists(const std::string& color_name) const; + + // Change from std::string to char*, avoind lots of unecessary string constructions + + // bool colorExists(const std::string& color_name) const; + bool colorExists(char const *name) const; + + // // loads colors from settings files bool loadFromSettings();