diff options
author | Dmitry Zaporozhan <dzaporozhan@productengine.com> | 2010-04-27 10:20:30 +0300 |
---|---|---|
committer | Dmitry Zaporozhan <dzaporozhan@productengine.com> | 2010-04-27 10:20:30 +0300 |
commit | ca07973e3ebd0ed1b18325a077ba4553d051c662 (patch) | |
tree | a0f9de9cab2b374195301cb6b783af7750d603f4 | |
parent | 17f2234a96d11a78726a77285b77dd25721ab8ce (diff) |
Making use of LLCommonUtils::computeDifference.
Replaced duplicating code with generic function LLCommonUtils::computeDifference()
Reviewed by Vadim Savchuk - https://codereview.productengine.com/secondlife/r/313/
--HG--
branch : product-engine
-rw-r--r-- | indra/llcommon/llcommonutils.h | 5 | ||||
-rw-r--r-- | indra/newview/llavatarlist.cpp | 18 | ||||
-rw-r--r-- | indra/newview/lloutfitslist.cpp | 51 | ||||
-rw-r--r-- | indra/newview/lloutfitslist.h | 6 |
4 files changed, 43 insertions, 37 deletions
diff --git a/indra/llcommon/llcommonutils.h b/indra/llcommon/llcommonutils.h index f769ab87d3..ad0d884e37 100644 --- a/indra/llcommon/llcommonutils.h +++ b/indra/llcommon/llcommonutils.h @@ -38,6 +38,11 @@ namespace LLCommonUtils * Computes difference between 'vnew' and 'vcur' vectors. * Items present in 'vnew' and missing in 'vcur' are treated as added and are copied into 'vadded' * Items missing in 'vnew' and present in 'vcur' are treated as removed and are copied into 'vremoved' + * + * @param vnew[in] - incoming IDs + * @param vcur[in] - current IDs + * @param vadded[out] - difference between incoming and current IDS - added IDs + * @param vremoved[out] - difference between incoming and current IDS - removed IDs */ LL_COMMON_API void computeDifference( const uuid_vec_t& vnew, diff --git a/indra/newview/llavatarlist.cpp b/indra/newview/llavatarlist.cpp index 8ba47b5198..fd0b20281b 100644 --- a/indra/newview/llavatarlist.cpp +++ b/indra/newview/llavatarlist.cpp @@ -34,6 +34,7 @@ // common #include "lltrans.h" +#include "llcommonutils.h" #include "llavatarlist.h" #include "llagentdata.h" // for comparator @@ -404,7 +405,6 @@ void LLAvatarList::computeDifference( uuid_vec_t& vremoved) { uuid_vec_t vcur; - uuid_vec_t vnew = vnew_unsorted; // Convert LLSDs to LLUUIDs. { @@ -415,21 +415,7 @@ void LLAvatarList::computeDifference( vcur.push_back(vcur_values[i].asUUID()); } - std::sort(vcur.begin(), vcur.end()); - std::sort(vnew.begin(), vnew.end()); - - uuid_vec_t::iterator it; - size_t maxsize = llmax(vcur.size(), vnew.size()); - vadded.resize(maxsize); - vremoved.resize(maxsize); - - // what to remove - it = set_difference(vcur.begin(), vcur.end(), vnew.begin(), vnew.end(), vremoved.begin()); - vremoved.erase(it, vremoved.end()); - - // what to add - it = set_difference(vnew.begin(), vnew.end(), vcur.begin(), vcur.end(), vadded.begin()); - vadded.erase(it, vadded.end()); + LLCommonUtils::computeDifference(vnew_unsorted, vcur, vadded, vremoved); } // Refresh shown time of our last interaction with all listed avatars. diff --git a/indra/newview/lloutfitslist.cpp b/indra/newview/lloutfitslist.cpp index 1c627d452f..1215272685 100644 --- a/indra/newview/lloutfitslist.cpp +++ b/indra/newview/lloutfitslist.cpp @@ -36,6 +36,9 @@ // llcommon #include "llcommonutils.h" +// llcommon +#include "llcommonutils.h" + #include "llaccordionctrl.h" #include "llaccordionctrltab.h" #include "llinventoryfunctions.h" @@ -119,31 +122,11 @@ void LLOutfitsList::refreshList(const LLUUID& category_id) LLInventoryModel::EXCLUDE_TRASH, is_category); - uuid_vec_t vnew; - - // Creating a vector of newly collected sub-categories UUIDs. - for (LLInventoryModel::cat_array_t::const_iterator iter = cat_array.begin(); - iter != cat_array.end(); - ++iter) - { - vnew.push_back((*iter)->getUUID()); - } - - uuid_vec_t vcur; - - // Creating a vector of currently displayed sub-categories UUIDs. - for (outfits_map_t::const_iterator iter = mOutfitsMap.begin(); - iter != mOutfitsMap.end(); - ++iter) - { - vcur.push_back((*iter).first); - } - uuid_vec_t vadded; uuid_vec_t vremoved; // Create added and removed items vectors. - LLCommonUtils::computeDifference(vnew, vcur, vadded, vremoved); + computeDifference(cat_array, vadded, vremoved); // Handle added tabs. for (uuid_vec_t::const_iterator iter = vadded.begin(); @@ -274,4 +257,30 @@ LLXMLNodePtr LLOutfitsList::getAccordionTabXMLNode() return xmlNode; } +void LLOutfitsList::computeDifference( + const LLInventoryModel::cat_array_t& vcats, + uuid_vec_t& vadded, + uuid_vec_t& vremoved) +{ + uuid_vec_t vnew; + // Creating a vector of newly collected sub-categories UUIDs. + for (LLInventoryModel::cat_array_t::const_iterator iter = vcats.begin(); + iter != vcats.end(); + iter++) + { + vnew.push_back((*iter)->getUUID()); + } + + uuid_vec_t vcur; + // Creating a vector of currently displayed sub-categories UUIDs. + for (outfits_map_t::const_iterator iter = mOutfitsMap.begin(); + iter != mOutfitsMap.end(); + iter++) + { + vcur.push_back((*iter).first); + } + + LLCommonUtils::computeDifference(vnew, vcur, vadded, vremoved); +} + // EOF diff --git a/indra/newview/lloutfitslist.h b/indra/newview/lloutfitslist.h index de14c15415..2d103ea356 100644 --- a/indra/newview/lloutfitslist.h +++ b/indra/newview/lloutfitslist.h @@ -35,6 +35,7 @@ #include "llpanel.h" // newview +#include "llinventorymodel.h" #include "llinventoryobserver.h" class LLAccordionCtrl; @@ -79,6 +80,11 @@ private: */ LLXMLNodePtr getAccordionTabXMLNode(); + /** + * Wrapper for LLCommonUtils::computeDifference. @see LLCommonUtils::computeDifference + */ + void computeDifference(const LLInventoryModel::cat_array_t& vcats, uuid_vec_t& vadded, uuid_vec_t& vremoved); + LLInventoryCategoriesObserver* mCategoriesObserver; |