Clean up focused UI menu code and opt out a common dynamic_cast

Initially I null checked this in testing and debugging, and since
then this code has just lowered performance, ugh.
This commit is contained in:
Liru Færs
2019-09-07 13:32:30 -04:00
parent 46f57756e7
commit 497012f98e
2 changed files with 26 additions and 21 deletions

View File

@@ -386,9 +386,15 @@ const std::string& LLTextEditor::getMenuSegmentUrl() const
static LLTextEditor* get_focused_text_editor() static LLTextEditor* get_focused_text_editor()
{ {
auto* list = dynamic_cast<LLTextEditor*>(gFocusMgr.getKeyboardFocus()); auto* te =
llassert(list); // This listener only applies to lists #ifdef SHOW_ASSERT
return list; dynamic_cast<LLTextEditor*>
#else
static_cast<LLTextEditor*>
#endif
(gFocusMgr.getKeyboardFocus());
llassert(te); // This listener only applies to text editors
return te;
} }
class ContextText : public LLMemberListener<LLView> class ContextText : public LLMemberListener<LLView>

View File

@@ -9038,30 +9038,36 @@ class VisibleNotSecondLife : public view_listener_t
} }
}; };
LLScrollListCtrl* get_focused_list() template<typename T> T* get_focused()
{ {
LLScrollListCtrl* list = dynamic_cast<LLScrollListCtrl*>(gFocusMgr.getKeyboardFocus()); T* t =
llassert(list); // This listener only applies to lists #ifdef SHOW_ASSERT
return list; dynamic_cast<T*>
#else
static_cast<T*>
#endif
(gFocusMgr.getKeyboardFocus());
llassert(t); // This listener only applies to T
return t;
} }
S32 get_focused_list_num_selected() S32 get_focused_list_num_selected()
{ {
if (LLScrollListCtrl* list = get_focused_list()) if (auto list = get_focused<LLScrollListCtrl>())
return list->getNumSelected(); return list->getNumSelected();
return 0; return 0;
} }
const LLUUID get_focused_list_id_selected() const LLUUID get_focused_list_id_selected()
{ {
if (LLScrollListCtrl* list = get_focused_list()) if (auto list = get_focused<LLScrollListCtrl>())
return list->getStringUUIDSelectedItem(); return list->getStringUUIDSelectedItem();
return LLUUID::null; return LLUUID::null;
} }
const uuid_vec_t get_focused_list_ids_selected() const uuid_vec_t get_focused_list_ids_selected()
{ {
if (LLScrollListCtrl* list = get_focused_list()) if (auto list = get_focused<LLScrollListCtrl>())
return list->getSelectedIDs(); return list->getSelectedIDs();
return uuid_vec_t(); return uuid_vec_t();
} }
@@ -9109,7 +9115,7 @@ class ListEnableCall : public view_listener_t
{ {
bool handleEvent(LLPointer<LLEvent> event, const LLSD& userdata) bool handleEvent(LLPointer<LLEvent> event, const LLSD& userdata)
{ {
LLScrollListCtrl* list = get_focused_list(); auto list = get_focused<LLScrollListCtrl>();
if (!list) return false; if (!list) return false;
gMenuHolder->findControl(userdata["control"].asString())->setValue(LLAvatarActions::canCall()); gMenuHolder->findControl(userdata["control"].asString())->setValue(LLAvatarActions::canCall());
return true; return true;
@@ -9517,18 +9523,11 @@ struct MenuSLURLDict : public LLSingleton<MenuSLURLDict>
} }
}; };
LLMediaCtrl* get_focused_media_ctrl()
{
auto media_ctrl = dynamic_cast<LLMediaCtrl*>(gFocusMgr.getKeyboardFocus());
llassert(media_ctrl); // This listener only applies to media_ctrls
return media_ctrl;
}
class MediaCtrlCopyURL : public view_listener_t class MediaCtrlCopyURL : public view_listener_t
{ {
bool handleEvent(LLPointer<LLEvent> event, const LLSD& userdata) bool handleEvent(LLPointer<LLEvent> event, const LLSD& userdata)
{ {
get_focused_media_ctrl()->onCopyURL(); get_focused<LLMediaCtrl>()->onCopyURL();
return true; return true;
} }
}; };
@@ -9537,7 +9536,7 @@ class MediaCtrlWebInspector : public view_listener_t
{ {
bool handleEvent(LLPointer<LLEvent> event, const LLSD& userdata) bool handleEvent(LLPointer<LLEvent> event, const LLSD& userdata)
{ {
get_focused_media_ctrl()->onOpenWebInspector(); get_focused<LLMediaCtrl>()->onOpenWebInspector();
return true; return true;
} }
}; };
@@ -9546,7 +9545,7 @@ class MediaCtrlViewSource : public view_listener_t
{ {
bool handleEvent(LLPointer<LLEvent> event, const LLSD& userdata) bool handleEvent(LLPointer<LLEvent> event, const LLSD& userdata)
{ {
get_focused_media_ctrl()->onShowSource(); get_focused<LLMediaCtrl>()->onShowSource();
return true; return true;
} }
}; };