Use heterogeneous comparison for string_view map finds in LLControl and convert controlExists to string_view

master
Rye Mutt 2024-07-01 22:25:56 -04:00
parent 49d60e0ded
commit b0e30477e9
10 changed files with 25 additions and 23 deletions

View File

@ -226,11 +226,11 @@ void delete_and_clear_array(T*& ptr)
// foo[2] = "hello";
// const char* bar = get_ptr_in_map(foo, 2); // bar -> "hello"
// const char* baz = get_ptr_in_map(foo, 3); // baz == NULL
template <typename K, typename T>
inline T* get_ptr_in_map(const std::map<K,T*>& inmap, const K& key)
template <typename T>
inline typename T::mapped_type get_ptr_in_map(const T& inmap, typename T::key_type const& key)
{
// Typedef here avoids warnings because of new c++ naming rules.
typedef typename std::map<K,T*>::const_iterator map_iter;
typedef T::const_iterator map_iter;
map_iter iter = inmap.find(key);
if(iter == inmap.end())
{

View File

@ -439,7 +439,7 @@ LLNotificationTemplate::LLNotificationTemplate(const LLNotificationTemplate::Par
mSoundName("")
{
if (p.sound.isProvided()
&& LLUI::getInstance()->mSettingGroups["config"]->controlExists(p.sound))
&& LLUI::getInstance()->mSettingGroups["config"]->controlExists(p.sound()))
{
mSoundName = p.sound;
}

View File

@ -367,7 +367,7 @@ void LLUI::glRectToScreen(const LLRect& gl, LLRect *screen)
}
LLControlGroup& LLUI::getControlControlGroup (const std::string& controlname)
LLControlGroup& LLUI::getControlControlGroup (std::string_view controlname)
{
for (settings_map_t::iterator itor = mSettingGroups.begin();
itor != mSettingGroups.end(); ++itor)

View File

@ -115,7 +115,7 @@ typedef void (*LLUIAudioCallback)(const LLUUID& uuid);
class LLUI : public LLParamSingleton<LLUI>
{
public:
typedef std::map<std::string, LLControlGroup*> settings_map_t;
typedef std::map<std::string, LLControlGroup*, std::less<> > settings_map_t;
private:
LLSINGLETON(LLUI , const settings_map_t &settings,
@ -295,7 +295,7 @@ public:
void screenRectToGL(const LLRect& screen, LLRect *gl);
void glRectToScreen(const LLRect& gl, LLRect *screen);
// Returns the control group containing the control name, or the default group
LLControlGroup& getControlControlGroup (const std::string& controlname);
LLControlGroup& getControlControlGroup (std::string_view controlname);
F32 getMouseIdleTime() { return mMouseIdleTimer.getElapsedTimeF32(); }
void resetMouseIdleTimer() { mMouseIdleTimer.reset(); }
LLWindow* getWindow() { return mWindow; }

View File

@ -135,7 +135,7 @@ void LLUICtrl::initFromParams(const Params& p)
{
if (p.enabled_controls.enabled.isChosen())
{
LLControlVariable* control = findControl(p.enabled_controls.enabled);
LLControlVariable* control = findControl(p.enabled_controls.enabled());
if (control)
{
setEnabledControlVariable(control);
@ -149,7 +149,7 @@ void LLUICtrl::initFromParams(const Params& p)
}
else if(p.enabled_controls.disabled.isChosen())
{
LLControlVariable* control = findControl(p.enabled_controls.disabled);
LLControlVariable* control = findControl(p.enabled_controls.disabled());
if (control)
{
setDisabledControlVariable(control);
@ -166,7 +166,7 @@ void LLUICtrl::initFromParams(const Params& p)
{
if (p.controls_visibility.visible.isChosen())
{
LLControlVariable* control = findControl(p.controls_visibility.visible);
LLControlVariable* control = findControl(p.controls_visibility.visible());
if (control)
{
setMakeVisibleControlVariable(control);
@ -180,7 +180,7 @@ void LLUICtrl::initFromParams(const Params& p)
}
else if (p.controls_visibility.invisible.isChosen())
{
LLControlVariable* control = findControl(p.controls_visibility.invisible);
LLControlVariable* control = findControl(p.controls_visibility.invisible());
if (control)
{
setMakeInvisibleControlVariable(control);

View File

@ -2312,18 +2312,20 @@ LLView* LLView::findSnapEdge(S32& new_edge_val, const LLCoordGL& mouse_dir, ESna
//-----------------------------------------------------------------------------
LLControlVariable *LLView::findControl(const std::string& name)
LLControlVariable *LLView::findControl(std::string_view name)
{
auto uiInst = LLUI::getInstance();
// parse the name to locate which group it belongs to
std::size_t key_pos= name.find(".");
if(key_pos!= std::string::npos )
if(key_pos != std::string_view::npos )
{
std::string control_group_key = name.substr(0, key_pos);
std::string_view control_group_key = name.substr(0, key_pos);
LLControlVariable* control;
// check if it's in the control group that name indicated
if(LLUI::getInstance()->mSettingGroups[control_group_key])
auto it = uiInst->mSettingGroups.find(control_group_key);
if(it != uiInst->mSettingGroups.end() && it->second)
{
control = LLUI::getInstance()->mSettingGroups[control_group_key]->getControl(name);
control = it->second->getControl(name);
if (control)
{
return control;
@ -2331,7 +2333,7 @@ LLControlVariable *LLView::findControl(const std::string& name)
}
}
LLControlGroup& control_group = LLUI::getInstance()->getControlControlGroup(name);
LLControlGroup& control_group = uiInst->getControlControlGroup(name);
return control_group.getControl(name);
}

View File

@ -416,7 +416,7 @@ public:
void screenRectToLocal( const LLRect& screen, LLRect* local ) const;
void localRectToScreen( const LLRect& local, LLRect* screen ) const;
LLControlVariable *findControl(const std::string& name);
LLControlVariable *findControl(std::string_view name);
const child_list_t* getChildList() const { return &mChildList; }
child_list_const_iter_t beginChild() const { return mChildList.begin(); }

View File

@ -348,7 +348,7 @@ LLPointer<LLControlVariable> LLControlGroup::getControl(std::string_view name)
incrCount(name);
}
ctrl_name_table_t::iterator iter = mNameTable.find(name.data());
ctrl_name_table_t::iterator iter = mNameTable.find(name);
return iter == mNameTable.end() ? LLPointer<LLControlVariable>() : iter->second;
}
@ -657,7 +657,7 @@ LLSD LLControlGroup::asLLSD(bool diffs_only)
return result;
}
bool LLControlGroup::controlExists(const std::string& name)
bool LLControlGroup::controlExists(std::string_view name)
{
ctrl_name_table_t::iterator iter = mNameTable.find(name);
return iter != mNameTable.end();

View File

@ -189,7 +189,7 @@ class LLControlGroup : public LLInstanceTracker<LLControlGroup, std::string>
LOG_CLASS(LLControlGroup);
protected:
typedef std::map<std::string, LLControlVariablePtr > ctrl_name_table_t;
typedef std::map<std::string, LLControlVariablePtr, std::less<> > ctrl_name_table_t;
ctrl_name_table_t mNameTable;
static const std::string mTypeString[TYPE_COUNT];
@ -295,7 +295,7 @@ public:
}
}
bool controlExists(const std::string& name);
bool controlExists(std::string_view name);
// Returns number of controls loaded, 0 if failed
// If require_declaration is false, will auto-declare controls it finds

View File

@ -2393,7 +2393,7 @@ bool LLAppViewer::loadSettingsFromDirectory(const std::string& location_key,
std::string full_settings_path;
if (file.file_name_setting.isProvided()
&& gSavedSettings.controlExists(file.file_name_setting))
&& gSavedSettings.controlExists(file.file_name_setting()))
{
// try to find filename stored in file_name_setting control
full_settings_path = gSavedSettings.getString(file.file_name_setting());