Skip to content

Commit 6686fc2

Browse files
committed
#5046 Optimize outfit's onRefreshComplete #3
1 parent 3cab5ca commit 6686fc2

File tree

4 files changed

+45
-39
lines changed

4 files changed

+45
-39
lines changed

indra/newview/lloutfitslist.cpp

Lines changed: 32 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@
5454
#include "llvoavatarself.h"
5555
#include "llwearableitemslist.h"
5656

57-
static bool is_tab_header_clicked(LLAccordionCtrlTab* tab, S32 y);
57+
static bool is_tab_header_clicked(LLOutfitAccordionCtrlTab* tab, S32 y);
5858

5959
static const LLOutfitTabNameComparator OUTFIT_TAB_NAME_COMPARATOR;
6060
static const LLOutfitTabFavComparator OUTFIT_TAB_FAV_COMPARATOR;
@@ -246,7 +246,10 @@ void LLOutfitsList::updateAddedCategory(LLUUID cat_id)
246246
list->setCommitCallback(boost::bind(&LLOutfitsList::onListSelectionChange, this, _1));
247247

248248
// Setting list refresh callback to apply filter on list change.
249-
list->setRefreshCompleteCallback(boost::bind(&LLOutfitsList::onRefreshComplete, this, _1));
249+
list->setRefreshCompleteCallback([this, tab](LLUICtrl* ctrl, const LLSD& sd)
250+
{
251+
onRefreshComplete(ctrl, tab);
252+
});
250253

251254
list->setRightMouseDownCallback(boost::bind(&LLOutfitsList::onWearableItemsListRightClick, this, _1, _2, _3));
252255

@@ -294,7 +297,7 @@ void LLOutfitsList::updateRemovedCategory(LLUUID cat_id)
294297
if (outfits_iter != mOutfitsMap.end())
295298
{
296299
const LLUUID& outfit_id = outfits_iter->first;
297-
LLAccordionCtrlTab* tab = outfits_iter->second;
300+
LLOutfitAccordionCtrlTab* tab = outfits_iter->second;
298301

299302
// An outfit is removed from the list. Do the following:
300303
// 1. Remove outfit category from observer to stop monitoring its changes.
@@ -322,11 +325,11 @@ void LLOutfitsList::onHighlightBaseOutfit(LLUUID base_id, LLUUID prev_id)
322325
{
323326
if (mOutfitsMap[prev_id])
324327
{
325-
((LLOutfitAccordionCtrlTab*)mOutfitsMap[prev_id])->setOutfitSelected(false);
328+
mOutfitsMap[prev_id]->setOutfitSelected(false);
326329
}
327330
if (mOutfitsMap[base_id])
328331
{
329-
((LLOutfitAccordionCtrlTab*)mOutfitsMap[base_id])->setOutfitSelected(true);
332+
mOutfitsMap[base_id]->setOutfitSelected(true);
330333
}
331334
}
332335

@@ -370,7 +373,7 @@ void LLOutfitsList::onSetSelectedOutfitByUUID(const LLUUID& outfit_uuid)
370373
{
371374
if (outfit_uuid == iter->first)
372375
{
373-
LLAccordionCtrlTab* tab = iter->second;
376+
LLOutfitAccordionCtrlTab* tab = iter->second;
374377
if (!tab) continue;
375378

376379
LLWearableItemsList* list = dynamic_cast<LLWearableItemsList*>(tab->getAccordionView());
@@ -464,7 +467,7 @@ void LLOutfitsList::onCollapseAllFolders()
464467
iter != mOutfitsMap.end();
465468
++iter)
466469
{
467-
LLAccordionCtrlTab* tab = iter->second;
470+
LLOutfitAccordionCtrlTab* tab = iter->second;
468471
if(tab && tab->isExpanded())
469472
{
470473
tab->changeOpenClose(true);
@@ -478,7 +481,7 @@ void LLOutfitsList::onExpandAllFolders()
478481
iter != mOutfitsMap.end();
479482
++iter)
480483
{
481-
LLAccordionCtrlTab* tab = iter->second;
484+
LLOutfitAccordionCtrlTab* tab = iter->second;
482485
if(tab && !tab->isExpanded())
483486
{
484487
tab->changeOpenClose(false);
@@ -501,7 +504,7 @@ void LLOutfitsList::updateChangedCategoryName(LLViewerInventoryCategory *cat, st
501504
if (outfits_iter != mOutfitsMap.end())
502505
{
503506
// Update tab name with the new category name.
504-
LLOutfitAccordionCtrlTab* tab = (LLOutfitAccordionCtrlTab*) outfits_iter->second;
507+
LLOutfitAccordionCtrlTab* tab = outfits_iter->second;
505508
if (tab)
506509
{
507510
tab->setName(name);
@@ -554,7 +557,7 @@ void LLOutfitsList::deselectOutfit(const LLUUID& category_id)
554557
LLOutfitListBase::deselectOutfit(category_id);
555558
}
556559

557-
void LLOutfitsList::restoreOutfitSelection(LLAccordionCtrlTab* tab, const LLUUID& category_id)
560+
void LLOutfitsList::restoreOutfitSelection(LLOutfitAccordionCtrlTab* tab, const LLUUID& category_id)
558561
{
559562
// Try restoring outfit selection after filtering.
560563
if (mAccordion->getSelectedTab() == tab)
@@ -563,27 +566,21 @@ void LLOutfitsList::restoreOutfitSelection(LLAccordionCtrlTab* tab, const LLUUID
563566
}
564567
}
565568

566-
void LLOutfitsList::onRefreshComplete(LLUICtrl* ctrl)
569+
void LLOutfitsList::onRefreshComplete(LLUICtrl* ctrl, LLOutfitAccordionCtrlTab* tab)
567570
{
568571
if (!ctrl || getFilterSubString().empty())
569572
return;
570573

571-
LL_PROFILE_ZONE_SCOPED;
572-
573-
// TODO: We are doing it multiple times per frame on init
574-
// as multiple lists are refreshing. Needs improvements.
575-
for (outfits_map_t::iterator
576-
iter = mOutfitsMap.begin(),
577-
iter_end = mOutfitsMap.end();
578-
iter != iter_end; ++iter)
574+
LLWearableItemsList* list = dynamic_cast<LLWearableItemsList*>(tab->getAccordionView());
575+
if (list != ctrl)
579576
{
580-
LLAccordionCtrlTab* tab = iter->second;
581-
if (!tab) continue;
582-
583-
LLWearableItemsList* list = dynamic_cast<LLWearableItemsList*>(tab->getAccordionView());
584-
if (list != ctrl) continue;
585-
586-
applyFilterToTab(iter->first, tab, getFilterSubString());
577+
llassert(false);
578+
LL_WARNS() << "LLOutfitsList::onRefreshComplete: ctrl does not match tab's list!" << LL_ENDL;
579+
return;
580+
}
581+
if (tab->getFilterGeneration() != getFilterGeneration())
582+
{
583+
applyFilterToTab(tab->getFolderID(), tab, getFilterSubString());
587584
}
588585
}
589586

@@ -596,7 +593,7 @@ void LLOutfitsList::onFilterSubStringChanged(const std::string& new_string, cons
596593
while (iter != iter_end)
597594
{
598595
const LLUUID& category_id = iter->first;
599-
LLAccordionCtrlTab* tab = iter++->second;
596+
LLOutfitAccordionCtrlTab* tab = iter++->second;
600597
if (!tab) continue;
601598

602599
LLWearableItemsList* list = dynamic_cast<LLWearableItemsList*>(tab->getAccordionView());
@@ -635,9 +632,10 @@ void LLOutfitsList::onFilterSubStringChanged(const std::string& new_string, cons
635632

636633
void LLOutfitsList::applyFilterToTab(
637634
const LLUUID& category_id,
638-
LLAccordionCtrlTab* tab,
635+
LLOutfitAccordionCtrlTab* tab,
639636
const std::string& filter_substring)
640637
{
638+
LL_PROFILE_ZONE_SCOPED;
641639
if (!tab) return;
642640
LLWearableItemsList* list = dynamic_cast<LLWearableItemsList*>(tab->getAccordionView());
643641
if (!list) return;
@@ -649,6 +647,7 @@ void LLOutfitsList::applyFilterToTab(
649647
LLStringUtil::toUpper(cur_filter);
650648

651649
tab->setTitle(tab->getTitle(), cur_filter);
650+
tab->setFilterGeneration(getFilterGeneration());
652651

653652
if (std::string::npos == title.find(cur_filter))
654653
{
@@ -772,7 +771,7 @@ void LLOutfitsList::onCOFChanged()
772771
outfits_map_t::iterator map_iter = mOutfitsMap.begin(), map_end = mOutfitsMap.end();
773772
while (map_iter != map_end)
774773
{
775-
LLAccordionCtrlTab* tab = (map_iter++)->second;
774+
LLOutfitAccordionCtrlTab* tab = (map_iter++)->second;
776775
if (!tab) continue;
777776

778777
LLWearableItemsList* list = dynamic_cast<LLWearableItemsList*>(tab->getAccordionView());
@@ -803,7 +802,7 @@ void LLOutfitsList::sortOutfits()
803802

804803
void LLOutfitsList::onOutfitRightClick(LLUICtrl* ctrl, S32 x, S32 y, const LLUUID& cat_id)
805804
{
806-
LLAccordionCtrlTab* tab = dynamic_cast<LLAccordionCtrlTab*>(ctrl);
805+
LLOutfitAccordionCtrlTab* tab = dynamic_cast<LLOutfitAccordionCtrlTab*>(ctrl);
807806
if (mOutfitMenu && is_tab_header_clicked(tab, y) && cat_id.notNull())
808807
{
809808
// Focus tab header to trigger tab selection change.
@@ -826,7 +825,7 @@ void LLOutfitsList::handleInvFavColorChange()
826825
++iter)
827826
{
828827
if (!iter->second) continue;
829-
LLOutfitAccordionCtrlTab* tab = (LLOutfitAccordionCtrlTab*)iter->second;
828+
LLOutfitAccordionCtrlTab* tab = iter->second;
830829

831830
// refresh font color
832831
tab->setFavorite(tab->getFavorite());
@@ -853,7 +852,7 @@ void LLOutfitsList::onChangeSortOrder(const LLSD& userdata)
853852
{
854853
for (outfits_map_t::value_type& outfit : mOutfitsMap)
855854
{
856-
LLAccordionCtrlTab* tab = outfit.second;
855+
LLOutfitAccordionCtrlTab* tab = outfit.second;
857856
const LLUUID& category_id = outfit.first;
858857
if (!tab) continue;
859858

@@ -894,7 +893,7 @@ LLOutfitListGearMenuBase* LLOutfitsList::createGearMenu()
894893
}
895894

896895

897-
bool is_tab_header_clicked(LLAccordionCtrlTab* tab, S32 y)
896+
bool is_tab_header_clicked(LLOutfitAccordionCtrlTab* tab, S32 y)
898897
{
899898
if(!tab || !tab->getHeaderVisible()) return false;
900899

indra/newview/lloutfitslist.h

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -38,14 +38,13 @@
3838
#include "lltoggleablemenu.h"
3939
#include "llviewermenu.h"
4040

41-
class LLAccordionCtrlTab;
41+
class LLOutfitAccordionCtrlTab;
4242
class LLInventoryCategoriesObserver;
4343
class LLOutfitListGearMenuBase;
4444
class LLOutfitListSortMenuBase;
4545
class LLWearableItemsList;
4646
class LLListContextMenu;
4747

48-
4948
/**
5049
* @class LLOutfitTabNameComparator
5150
*
@@ -266,7 +265,10 @@ class LLOutfitAccordionCtrlTab : public LLAccordionCtrlTab
266265

267266
void setFavorite(bool is_favorite);
268267
bool getFavorite() const { return mIsFavorite; }
268+
LLUUID getFolderID() const { return mFolderID; }
269269
void setOutfitSelected(bool val);
270+
U32 getFilterGeneration() const { return mFilterGeneration; }
271+
void setFilterGeneration(U32 generation) { mFilterGeneration = generation; }
270272

271273
static LLUIImage* sFavoriteIcon;
272274
static LLUIColor sFgColor;
@@ -284,6 +286,7 @@ class LLOutfitAccordionCtrlTab : public LLAccordionCtrlTab
284286
LLUUID mFolderID;
285287
bool mIsFavorite = false;
286288
bool mIsSelected = false;
289+
U32 mFilterGeneration = 0;
287290
};
288291
/**
289292
* @class LLOutfitsList
@@ -386,20 +389,20 @@ class LLOutfitsList : public LLOutfitListBase
386389
*
387390
* A tab may be hidden if it doesn't match current filter.
388391
*/
389-
void restoreOutfitSelection(LLAccordionCtrlTab* tab, const LLUUID& category_id);
392+
void restoreOutfitSelection(LLOutfitAccordionCtrlTab* tab, const LLUUID& category_id);
390393

391394
/**
392395
* Called upon list refresh event to update tab visibility depending on
393396
* the results of applying filter to the title and list items of the tab.
394397
*/
395-
void onRefreshComplete(LLUICtrl* ctrl);
398+
void onRefreshComplete(LLUICtrl* ctrl, LLOutfitAccordionCtrlTab* tab);
396399

397400
/**
398401
* Applies filter to the given tab
399402
*
400403
* @see applyFilter()
401404
*/
402-
void applyFilterToTab(const LLUUID& category_id, LLAccordionCtrlTab* tab, const std::string& filter_substring);
405+
void applyFilterToTab(const LLUUID& category_id, LLOutfitAccordionCtrlTab* tab, const std::string& filter_substring);
403406

404407
/**
405408
* Returns true if all selected items can be worn.
@@ -426,7 +429,7 @@ class LLOutfitsList : public LLOutfitListBase
426429
typedef wearables_lists_map_t::value_type wearables_lists_map_value_t;
427430
wearables_lists_map_t mSelectedListsMap;
428431

429-
typedef std::map<LLUUID, LLAccordionCtrlTab*> outfits_map_t;
432+
typedef std::map<LLUUID, LLOutfitAccordionCtrlTab*> outfits_map_t;
430433
typedef outfits_map_t::value_type outfits_map_value_t;
431434
outfits_map_t mOutfitsMap;
432435

indra/newview/llpanelappearancetab.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ void LLPanelAppearanceTab::setFilterSubString(const std::string& new_string)
4040
{
4141
std::string old_string = mFilterSubString;
4242
mFilterSubString = new_string;
43+
mFilterGeneration++;
4344
onFilterSubStringChanged(mFilterSubString, old_string);
4445
}
4546

@@ -52,6 +53,7 @@ void LLPanelAppearanceTab::checkFilterSubString()
5253
{
5354
std::string old_string = mFilterSubString;
5455
mFilterSubString = sRecentFilterSubString;
56+
mFilterGeneration++;
5557
onFilterSubStringChanged(mFilterSubString, old_string);
5658
}
5759
}

indra/newview/llpanelappearancetab.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ class LLPanelAppearanceTab : public LLPanel
4848
virtual void getSelectedItemsUUIDs(uuid_vec_t& selected_uuids) const {}
4949

5050
const std::string& getFilterSubString() { return mFilterSubString; }
51+
U32 getFilterGeneration() { return mFilterGeneration; }
5152

5253
virtual void updateMenuItemsVisibility() = 0;
5354
virtual LLToggleableMenu* getGearMenu() = 0;
@@ -63,6 +64,7 @@ class LLPanelAppearanceTab : public LLPanel
6364

6465
private:
6566
std::string mFilterSubString;
67+
U32 mFilterGeneration = 0;
6668

6769
static std::string sRecentFilterSubString;
6870
};

0 commit comments

Comments
 (0)