From 497012f98e038373b2e417311585cf1d94cb4eda Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Liru=20F=C3=A6rs?= Date: Sat, 7 Sep 2019 13:32:30 -0400 Subject: [PATCH] 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. --- indra/llui/lltexteditor.cpp | 12 +++++++++--- indra/newview/llviewermenu.cpp | 35 +++++++++++++++++----------------- 2 files changed, 26 insertions(+), 21 deletions(-) diff --git a/indra/llui/lltexteditor.cpp b/indra/llui/lltexteditor.cpp index f1999410c..2e1c70baf 100644 --- a/indra/llui/lltexteditor.cpp +++ b/indra/llui/lltexteditor.cpp @@ -386,9 +386,15 @@ const std::string& LLTextEditor::getMenuSegmentUrl() const static LLTextEditor* get_focused_text_editor() { - auto* list = dynamic_cast(gFocusMgr.getKeyboardFocus()); - llassert(list); // This listener only applies to lists - return list; + auto* te = +#ifdef SHOW_ASSERT + dynamic_cast +#else + static_cast +#endif + (gFocusMgr.getKeyboardFocus()); + llassert(te); // This listener only applies to text editors + return te; } class ContextText : public LLMemberListener diff --git a/indra/newview/llviewermenu.cpp b/indra/newview/llviewermenu.cpp index a494a025d..291f0b17b 100644 --- a/indra/newview/llviewermenu.cpp +++ b/indra/newview/llviewermenu.cpp @@ -9038,30 +9038,36 @@ class VisibleNotSecondLife : public view_listener_t } }; -LLScrollListCtrl* get_focused_list() +template T* get_focused() { - LLScrollListCtrl* list = dynamic_cast(gFocusMgr.getKeyboardFocus()); - llassert(list); // This listener only applies to lists - return list; + T* t = +#ifdef SHOW_ASSERT + dynamic_cast +#else + static_cast +#endif + (gFocusMgr.getKeyboardFocus()); + llassert(t); // This listener only applies to T + return t; } S32 get_focused_list_num_selected() { - if (LLScrollListCtrl* list = get_focused_list()) + if (auto list = get_focused()) return list->getNumSelected(); return 0; } const LLUUID get_focused_list_id_selected() { - if (LLScrollListCtrl* list = get_focused_list()) + if (auto list = get_focused()) return list->getStringUUIDSelectedItem(); return LLUUID::null; } const uuid_vec_t get_focused_list_ids_selected() { - if (LLScrollListCtrl* list = get_focused_list()) + if (auto list = get_focused()) return list->getSelectedIDs(); return uuid_vec_t(); } @@ -9109,7 +9115,7 @@ class ListEnableCall : public view_listener_t { bool handleEvent(LLPointer event, const LLSD& userdata) { - LLScrollListCtrl* list = get_focused_list(); + auto list = get_focused(); if (!list) return false; gMenuHolder->findControl(userdata["control"].asString())->setValue(LLAvatarActions::canCall()); return true; @@ -9517,18 +9523,11 @@ struct MenuSLURLDict : public LLSingleton } }; -LLMediaCtrl* get_focused_media_ctrl() -{ - auto media_ctrl = dynamic_cast(gFocusMgr.getKeyboardFocus()); - llassert(media_ctrl); // This listener only applies to media_ctrls - return media_ctrl; -} - class MediaCtrlCopyURL : public view_listener_t { bool handleEvent(LLPointer event, const LLSD& userdata) { - get_focused_media_ctrl()->onCopyURL(); + get_focused()->onCopyURL(); return true; } }; @@ -9537,7 +9536,7 @@ class MediaCtrlWebInspector : public view_listener_t { bool handleEvent(LLPointer event, const LLSD& userdata) { - get_focused_media_ctrl()->onOpenWebInspector(); + get_focused()->onOpenWebInspector(); return true; } }; @@ -9546,7 +9545,7 @@ class MediaCtrlViewSource : public view_listener_t { bool handleEvent(LLPointer event, const LLSD& userdata) { - get_focused_media_ctrl()->onShowSource(); + get_focused()->onShowSource(); return true; } };