diff options
author | Rye Mutt <rye@alchemyviewer.org> | 2024-07-01 22:24:32 -0400 |
---|---|---|
committer | Rye Mutt <rye@alchemyviewer.org> | 2024-07-01 22:24:32 -0400 |
commit | 49d60e0ded52c095c834e9ca134b67282728b389 (patch) | |
tree | 02426a87a60b23c8efa308198278b2e52e41cfbd /indra/llui | |
parent | e834e77988fcf637ee0f3e4c5c0875e47044e324 (diff) |
Reduce string temporaries from LLFloaterReg find/get
Diffstat (limited to 'indra/llui')
-rw-r--r-- | indra/llui/llbutton.cpp | 2 | ||||
-rw-r--r-- | indra/llui/llfloaterreg.cpp | 165 | ||||
-rw-r--r-- | indra/llui/llfloaterreg.h | 36 | ||||
-rw-r--r-- | indra/llui/llfloaterreglistener.cpp | 10 | ||||
-rw-r--r-- | indra/llui/llui.cpp | 14 |
5 files changed, 122 insertions, 105 deletions
diff --git a/indra/llui/llbutton.cpp b/indra/llui/llbutton.cpp index 91044e5441..7912baf132 100644 --- a/indra/llui/llbutton.cpp +++ b/indra/llui/llbutton.cpp @@ -1273,7 +1273,7 @@ void LLButton::setFloaterToggle(LLUICtrl* ctrl, const LLSD& sdname) // Set the button control value (toggle state) to the floater visibility control (Sets the value as well) button->setControlVariable(LLFloater::getControlGroup()->getControl(vis_control_name)); // Set the clicked callback to toggle the floater - button->setClickedCallback(boost::bind(&LLFloaterReg::toggleInstance, sdname, LLSD())); + button->setClickedCallback([=](LLUICtrl* ctrl, const LLSD& param) -> void { LLFloaterReg::toggleInstance(sdname.asString(), LLSD()); }); } // static diff --git a/indra/llui/llfloaterreg.cpp b/indra/llui/llfloaterreg.cpp index fd5a370bc3..a818e72f59 100644 --- a/indra/llui/llfloaterreg.cpp +++ b/indra/llui/llfloaterreg.cpp @@ -40,9 +40,9 @@ LLFloaterReg::instance_list_t LLFloaterReg::sNullInstanceList; LLFloaterReg::instance_map_t LLFloaterReg::sInstanceMap; LLFloaterReg::build_map_t LLFloaterReg::sBuildMap; -std::map<std::string,std::string> LLFloaterReg::sGroupMap; +std::map<std::string, std::string, std::less<>> LLFloaterReg::sGroupMap; bool LLFloaterReg::sBlockShowFloaters = false; -std::set<std::string> LLFloaterReg::sAlwaysShowableList; +std::set<std::string, std::less<>> LLFloaterReg::sAlwaysShowableList; static LLFloaterRegListener sFloaterRegListener; @@ -58,27 +58,31 @@ void LLFloaterReg::add(const std::string& name, const std::string& filename, con } //static -bool LLFloaterReg::isRegistered(const std::string& name) +bool LLFloaterReg::isRegistered(std::string_view name) { return sBuildMap.find(name) != sBuildMap.end(); } //static -LLFloater* LLFloaterReg::getLastFloaterInGroup(const std::string& name) +LLFloater* LLFloaterReg::getLastFloaterInGroup(std::string_view name) { - const std::string& groupname = sGroupMap[name]; - if (!groupname.empty()) + auto it = sGroupMap.find(name); + if (it != sGroupMap.end()) { - instance_list_t& list = sInstanceMap[groupname]; - if (!list.empty()) + const std::string& groupname = it->second; + if (!groupname.empty()) { - for (instance_list_t::reverse_iterator iter = list.rbegin(); iter != list.rend(); ++iter) + instance_list_t& list = sInstanceMap[groupname]; + if (!list.empty()) { - LLFloater* inst = *iter; - - if (inst->getVisible() && !inst->isMinimized()) + for (instance_list_t::reverse_iterator iter = list.rbegin(), end = list.rend(); iter != end; ++iter) { - return inst; + LLFloater* inst = *iter; + + if (inst->getVisible() && !inst->isMinimized()) + { + return inst; + } } } } @@ -99,10 +103,8 @@ LLFloater* LLFloaterReg::getLastFloaterCascading() instance_list_t& instances = sInstanceMap[group_name]; - for (instance_list_t::const_iterator iter = instances.begin(); iter != instances.end(); ++iter) + for (LLFloater* inst : instances) { - LLFloater* inst = *iter; - if (inst->getVisible() && (inst->isPositioning(LLFloaterEnums::POSITIONING_CASCADING) || inst->isPositioning(LLFloaterEnums::POSITIONING_CASCADE_GROUP))) @@ -120,20 +122,23 @@ LLFloater* LLFloaterReg::getLastFloaterCascading() } //static -LLFloater* LLFloaterReg::findInstance(const std::string& name, const LLSD& key) +LLFloater* LLFloaterReg::findInstance(std::string_view name, const LLSD& key) { LLFloater* res = NULL; - const std::string& groupname = sGroupMap[name]; - if (!groupname.empty()) + auto it = sGroupMap.find(name); + if (it != sGroupMap.end()) { - instance_list_t& list = sInstanceMap[groupname]; - for (instance_list_t::iterator iter = list.begin(); iter != list.end(); ++iter) + const std::string& groupname = it->second; + if (!groupname.empty()) { - LLFloater* inst = *iter; - if (inst->matchesKey(key)) + instance_list_t& list = sInstanceMap[groupname]; + for (LLFloater* inst : list) { - res = inst; - break; + if (inst->matchesKey(key)) + { + res = inst; + break; + } } } } @@ -141,47 +146,55 @@ LLFloater* LLFloaterReg::findInstance(const std::string& name, const LLSD& key) } //static -LLFloater* LLFloaterReg::getInstance(const std::string& name, const LLSD& key) +LLFloater* LLFloaterReg::getInstance(std::string_view name, const LLSD& key) { LLFloater* res = findInstance(name, key); if (!res) { - const LLFloaterBuildFunc& build_func = sBuildMap[name].mFunc; - const std::string& xui_file = sBuildMap[name].mFile; - if (build_func) + auto it = sBuildMap.find(name); + if (it != sBuildMap.end()) { - const std::string& groupname = sGroupMap[name]; - if (!groupname.empty()) + const LLFloaterBuildFunc& build_func = it->second.mFunc; + const std::string& xui_file = it->second.mFile; + if (build_func) { - instance_list_t& list = sInstanceMap[groupname]; - - res = build_func(key); - if (!res) - { - LL_WARNS() << "Failed to build floater type: '" << name << "'." << LL_ENDL; - return NULL; - } - bool success = res->buildFromFile(xui_file); - if (!success) + auto it = sGroupMap.find(name); + if (it != sGroupMap.end()) { - LL_WARNS() << "Failed to build floater type: '" << name << "'." << LL_ENDL; - return NULL; + const std::string& groupname = it->second; + if (!groupname.empty()) + { + instance_list_t& list = sInstanceMap[groupname]; + + res = build_func(key); + if (!res) + { + LL_WARNS() << "Failed to build floater type: '" << name << "'." << LL_ENDL; + return NULL; + } + bool success = res->buildFromFile(xui_file); + if (!success) + { + LL_WARNS() << "Failed to build floater type: '" << name << "'." << LL_ENDL; + return NULL; + } + + // Note: key should eventually be a non optional LLFloater arg; for now, set mKey to be safe + if (res->mKey.isUndefined()) + { + res->mKey = key; + } + res->setInstanceName(std::string(name)); + + LLFloater* last_floater = (list.empty() ? NULL : list.back()); + + res->applyControlsAndPosition(last_floater); + + gFloaterView->adjustToFitScreen(res, false); + + list.push_back(res); + } } - - // Note: key should eventually be a non optional LLFloater arg; for now, set mKey to be safe - if (res->mKey.isUndefined()) - { - res->mKey = key; - } - res->setInstanceName(name); - - LLFloater *last_floater = (list.empty() ? NULL : list.back()); - - res->applyControlsAndPosition(last_floater); - - gFloaterView->adjustToFitScreen(res, false); - - list.push_back(res); } } if (!res) @@ -193,21 +206,25 @@ LLFloater* LLFloaterReg::getInstance(const std::string& name, const LLSD& key) } //static -LLFloater* LLFloaterReg::removeInstance(const std::string& name, const LLSD& key) +LLFloater* LLFloaterReg::removeInstance(std::string_view name, const LLSD& key) { LLFloater* res = NULL; - const std::string& groupname = sGroupMap[name]; - if (!groupname.empty()) + auto it = sGroupMap.find(name); + if (it != sGroupMap.end()) { - instance_list_t& list = sInstanceMap[groupname]; - for (instance_list_t::iterator iter = list.begin(); iter != list.end(); ++iter) + const std::string& groupname = it->second; + if (!groupname.empty()) { - LLFloater* inst = *iter; - if (inst->matchesKey(key)) + instance_list_t& list = sInstanceMap[groupname]; + for (instance_list_t::iterator iter = list.begin(); iter != list.end(); ++iter) { - res = inst; - list.erase(iter); - break; + LLFloater* inst = *iter; + if (inst->matchesKey(key)) + { + res = inst; + list.erase(iter); + break; + } } } } @@ -216,7 +233,7 @@ LLFloater* LLFloaterReg::removeInstance(const std::string& name, const LLSD& key //static // returns true if the instance existed -bool LLFloaterReg::destroyInstance(const std::string& name, const LLSD& key) +bool LLFloaterReg::destroyInstance(std::string_view name, const LLSD& key) { LLFloater* inst = removeInstance(name, key); if (inst) @@ -232,7 +249,7 @@ bool LLFloaterReg::destroyInstance(const std::string& name, const LLSD& key) // Iterators //static -LLFloaterReg::const_instance_list_t& LLFloaterReg::getFloaterList(const std::string& name) +LLFloaterReg::const_instance_list_t& LLFloaterReg::getFloaterList(std::string_view name) { instance_map_t::iterator iter = sInstanceMap.find(name); if (iter != sInstanceMap.end()) @@ -248,7 +265,7 @@ LLFloaterReg::const_instance_list_t& LLFloaterReg::getFloaterList(const std::str // Visibility Management //static -LLFloater* LLFloaterReg::showInstance(const std::string& name, const LLSD& key, bool focus) +LLFloater* LLFloaterReg::showInstance(std::string_view name, const LLSD& key, bool focus) { if( sBlockShowFloaters // see EXT-7090 @@ -266,7 +283,7 @@ LLFloater* LLFloaterReg::showInstance(const std::string& name, const LLSD& key, //static // returns true if the instance exists -bool LLFloaterReg::hideInstance(const std::string& name, const LLSD& key) +bool LLFloaterReg::hideInstance(std::string_view name, const LLSD& key) { LLFloater* instance = findInstance(name, key); if (instance) @@ -278,7 +295,7 @@ bool LLFloaterReg::hideInstance(const std::string& name, const LLSD& key) //static // returns true if the instance is visible when completed -bool LLFloaterReg::toggleInstance(const std::string& name, const LLSD& key) +bool LLFloaterReg::toggleInstance(std::string_view name, const LLSD& key) { LLFloater* instance = findInstance(name, key); if (instance && instance->isShown()) @@ -294,7 +311,7 @@ bool LLFloaterReg::toggleInstance(const std::string& name, const LLSD& key) //static // returns true if the instance exists and is visible (doesnt matter minimized or not) -bool LLFloaterReg::instanceVisible(const std::string& name, const LLSD& key) +bool LLFloaterReg::instanceVisible(std::string_view name, const LLSD& key) { LLFloater* instance = findInstance(name, key); return LLFloater::isVisible(instance); diff --git a/indra/llui/llfloaterreg.h b/indra/llui/llfloaterreg.h index 6a642cbb27..94a67c8d8b 100644 --- a/indra/llui/llfloaterreg.h +++ b/indra/llui/llfloaterreg.h @@ -51,26 +51,26 @@ public: // 2) We can change the key of a floater without altering the list. typedef std::list<LLFloater*> instance_list_t; typedef const instance_list_t const_instance_list_t; - typedef std::map<std::string, instance_list_t> instance_map_t; + typedef std::map<std::string, instance_list_t, std::less<>> instance_map_t; struct BuildData { LLFloaterBuildFunc mFunc; std::string mFile; }; - typedef std::map<std::string, BuildData> build_map_t; + typedef std::map<std::string, BuildData, std::less<>> build_map_t; private: friend class LLFloaterRegListener; static instance_list_t sNullInstanceList; static instance_map_t sInstanceMap; static build_map_t sBuildMap; - static std::map<std::string,std::string> sGroupMap; + static std::map<std::string, std::string, std::less<>> sGroupMap; static bool sBlockShowFloaters; /** * Defines list of floater names that can be shown despite state of sBlockShowFloaters. */ - static std::set<std::string> sAlwaysShowableList; + static std::set<std::string, std::less<>> sAlwaysShowableList; public: // Registration @@ -85,30 +85,30 @@ public: static void add(const std::string& name, const std::string& file, const LLFloaterBuildFunc& func, const std::string& groupname = LLStringUtil::null); - static bool isRegistered(const std::string& name); + static bool isRegistered(std::string_view name); // Helpers - static LLFloater* getLastFloaterInGroup(const std::string& name); + static LLFloater* getLastFloaterInGroup(std::string_view name); static LLFloater* getLastFloaterCascading(); // Find / get (create) / remove / destroy - static LLFloater* findInstance(const std::string& name, const LLSD& key = LLSD()); - static LLFloater* getInstance(const std::string& name, const LLSD& key = LLSD()); - static LLFloater* removeInstance(const std::string& name, const LLSD& key = LLSD()); - static bool destroyInstance(const std::string& name, const LLSD& key = LLSD()); + static LLFloater* findInstance(std::string_view name, const LLSD& key = LLSD()); + static LLFloater* getInstance(std::string_view name, const LLSD& key = LLSD()); + static LLFloater* removeInstance(std::string_view name, const LLSD& key = LLSD()); + static bool destroyInstance(std::string_view name, const LLSD& key = LLSD()); // Iterators - static const_instance_list_t& getFloaterList(const std::string& name); + static const_instance_list_t& getFloaterList(std::string_view name); // Visibility Management // return NULL if instance not found or can't create instance (no builder) - static LLFloater* showInstance(const std::string& name, const LLSD& key = LLSD(), bool focus = false); + static LLFloater* showInstance(std::string_view name, const LLSD& key = LLSD(), bool focus = false); // Close a floater (may destroy or set invisible) // return false if can't find instance - static bool hideInstance(const std::string& name, const LLSD& key = LLSD()); + static bool hideInstance(std::string_view name, const LLSD& key = LLSD()); // return true if instance is visible: - static bool toggleInstance(const std::string& name, const LLSD& key = LLSD()); - static bool instanceVisible(const std::string& name, const LLSD& key = LLSD()); + static bool toggleInstance(std::string_view name, const LLSD& key = LLSD()); + static bool instanceVisible(std::string_view name, const LLSD& key = LLSD()); static void showInitialVisibleInstances(); static void hideVisibleInstances(const std::set<std::string>& exceptions = std::set<std::string>()); @@ -133,19 +133,19 @@ public: // Typed find / get / show template <class T> - static T* findTypedInstance(const std::string& name, const LLSD& key = LLSD()) + static T* findTypedInstance(std::string_view name, const LLSD& key = LLSD()) { return dynamic_cast<T*>(findInstance(name, key)); } template <class T> - static T* getTypedInstance(const std::string& name, const LLSD& key = LLSD()) + static T* getTypedInstance(std::string_view name, const LLSD& key = LLSD()) { return dynamic_cast<T*>(getInstance(name, key)); } template <class T> - static T* showTypedInstance(const std::string& name, const LLSD& key = LLSD(), bool focus = false) + static T* showTypedInstance(std::string_view name, const LLSD& key = LLSD(), bool focus = false) { return dynamic_cast<T*>(showInstance(name, key, focus)); } diff --git a/indra/llui/llfloaterreglistener.cpp b/indra/llui/llfloaterreglistener.cpp index 88fa65e8f5..17641b8375 100644 --- a/indra/llui/llfloaterreglistener.cpp +++ b/indra/llui/llfloaterreglistener.cpp @@ -94,22 +94,22 @@ void LLFloaterRegListener::getBuildMap(const LLSD& event) const void LLFloaterRegListener::showInstance(const LLSD& event) const { - LLFloaterReg::showInstance(event["name"], event["key"], event["focus"]); + LLFloaterReg::showInstance(event["name"].asString(), event["key"], event["focus"]); } void LLFloaterRegListener::hideInstance(const LLSD& event) const { - LLFloaterReg::hideInstance(event["name"], event["key"]); + LLFloaterReg::hideInstance(event["name"].asString(), event["key"]); } void LLFloaterRegListener::toggleInstance(const LLSD& event) const { - LLFloaterReg::toggleInstance(event["name"], event["key"]); + LLFloaterReg::toggleInstance(event["name"].asString(), event["key"]); } void LLFloaterRegListener::instanceVisible(const LLSD& event) const { - sendReply(LLSDMap("visible", LLFloaterReg::instanceVisible(event["name"], event["key"])), + sendReply(LLSDMap("visible", LLFloaterReg::instanceVisible(event["name"].asString(), event["key"])), event); } @@ -119,7 +119,7 @@ void LLFloaterRegListener::clickButton(const LLSD& event) const LLReqID reqID(event); LLSD reply(reqID.makeResponse()); - LLFloater* floater = LLFloaterReg::findInstance(event["name"], event["key"]); + LLFloater* floater = LLFloaterReg::findInstance(event["name"].asString(), event["key"]); if (! LLFloater::isShown(floater)) { reply["type"] = "LLFloater"; diff --git a/indra/llui/llui.cpp b/indra/llui/llui.cpp index 66ec3ad9bd..f5c55a3d37 100644 --- a/indra/llui/llui.cpp +++ b/indra/llui/llui.cpp @@ -170,11 +170,11 @@ mHelpImpl(NULL) LLUICtrl::CommitCallbackRegistry::Registrar& reg = LLUICtrl::CommitCallbackRegistry::defaultRegistrar(); // Callbacks for associating controls with floater visibility: - reg.add("Floater.Toggle", boost::bind(&LLFloaterReg::toggleInstance, _2, LLSD())); - reg.add("Floater.ToggleOrBringToFront", boost::bind(&LLFloaterReg::toggleInstanceOrBringToFront, _2, LLSD())); - reg.add("Floater.Show", boost::bind(&LLFloaterReg::showInstance, _2, LLSD(), false)); - reg.add("Floater.ShowOrBringToFront", boost::bind(&LLFloaterReg::showInstanceOrBringToFront, _2, LLSD())); - reg.add("Floater.Hide", boost::bind(&LLFloaterReg::hideInstance, _2, LLSD())); + reg.add("Floater.Toggle", [](LLUICtrl* ctrl, const LLSD& param) -> void { LLFloaterReg::toggleInstance(param.asStringRef()); }); + reg.add("Floater.ToggleOrBringToFront", [](LLUICtrl* ctrl, const LLSD& param) -> void { LLFloaterReg::toggleInstanceOrBringToFront(param.asStringRef()); }); + reg.add("Floater.Show", [](LLUICtrl* ctrl, const LLSD& param) -> void { LLFloaterReg::showInstance(param.asStringRef(), LLSD(), false); }); + reg.add("Floater.ShowOrBringToFront", [](LLUICtrl* ctrl, const LLSD& param) -> void { LLFloaterReg::showInstanceOrBringToFront(param.asStringRef(), LLSD()); }); + reg.add("Floater.Hide", [](LLUICtrl* ctrl, const LLSD& param) -> void { LLFloaterReg::hideInstance(param.asStringRef()); }); // Button initialization callback for toggle buttons reg.add("Button.SetFloaterToggle", boost::bind(&LLButton::setFloaterToggle, _1, _2)); @@ -189,8 +189,8 @@ mHelpImpl(NULL) reg.add("Button.ToggleFloater", boost::bind(&LLButton::toggleFloaterAndSetToggleState, _1, _2)); // Used by menus along with Floater.Toggle to display visibility as a check-mark - LLUICtrl::EnableCallbackRegistry::defaultRegistrar().add("Floater.Visible", boost::bind(&LLFloaterReg::instanceVisible, _2, LLSD())); - LLUICtrl::EnableCallbackRegistry::defaultRegistrar().add("Floater.IsOpen", boost::bind(&LLFloaterReg::instanceVisible, _2, LLSD())); + LLUICtrl::EnableCallbackRegistry::defaultRegistrar().add("Floater.Visible", [](LLUICtrl* ctrl, const LLSD& param) -> bool { return LLFloaterReg::instanceVisible(param.asStringRef(), LLSD()); }); + LLUICtrl::EnableCallbackRegistry::defaultRegistrar().add("Floater.IsOpen", [](LLUICtrl* ctrl, const LLSD& param) -> bool { return LLFloaterReg::instanceVisible(param.asStringRef(), LLSD()); }); // Parse the master list of commands LLCommandManager::load(); |