From ca07973e3ebd0ed1b18325a077ba4553d051c662 Mon Sep 17 00:00:00 2001
From: Dmitry Zaporozhan <dzaporozhan@productengine.com>
Date: Tue, 27 Apr 2010 10:20:30 +0300
Subject: [PATCH] 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
---
 indra/llcommon/llcommonutils.h  |  5 ++++
 indra/newview/llavatarlist.cpp  | 18 ++----------
 indra/newview/lloutfitslist.cpp | 51 +++++++++++++++++++--------------
 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 f769ab87d36..ad0d884e37e 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 8ba47b5198d..fd0b20281b3 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 1c627d452fb..12152726850 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 de14c154158..2d103ea3565 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 @@ class LLOutfitsList : public LLPanel, public LLInventoryObserver
 	 */
 	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;
 
-- 
GitLab