From 1062164cfecf7637e48c6f4fb51fe12681470523 Mon Sep 17 00:00:00 2001
From: Andrey Kleshchev <andreykproductengine@lindenlab.com>
Date: Mon, 27 Apr 2020 20:18:44 +0300
Subject: [PATCH] SL-13119 Duplicate check was causing slowdowns

---
 indra/llui/llfolderviewmodel.h        | 12 +-----------
 indra/newview/llconversationmodel.cpp | 17 +++++++++++++++++
 indra/newview/llconversationmodel.h   |  1 +
 3 files changed, 19 insertions(+), 11 deletions(-)

diff --git a/indra/llui/llfolderviewmodel.h b/indra/llui/llfolderviewmodel.h
index f71a88c56e8..84a15390944 100644
--- a/indra/llui/llfolderviewmodel.h
+++ b/indra/llui/llfolderviewmodel.h
@@ -285,17 +285,7 @@ class LLFolderViewModelItemCommon : public LLFolderViewModelItem
 	typedef std::list<LLFolderViewModelItem*> child_list_t;
 
 	virtual void addChild(LLFolderViewModelItem* child) 
-	{ 
-		// Avoid duplicates: bail out if that child is already present in the list
-		// Note: this happens when models are created before views
-		child_list_t::const_iterator iter;
-		for (iter = mChildren.begin(); iter != mChildren.end(); iter++)
-		{
-			if (child == *iter)
-			{
-				return;
-			}
-		}
+	{
 		mChildren.push_back(child);
 		child->setParent(this); 
 		dirtyFilter();
diff --git a/indra/newview/llconversationmodel.cpp b/indra/newview/llconversationmodel.cpp
index c2581368899..4aa74a550cb 100644
--- a/indra/newview/llconversationmodel.cpp
+++ b/indra/newview/llconversationmodel.cpp
@@ -92,6 +92,23 @@ LLConversationItem::~LLConversationItem()
 	}
 }
 
+//virtual
+void LLConversationItem::addChild(LLFolderViewModelItem* child)
+{
+    // Avoid duplicates: bail out if that child is already present in the list
+    // Note: this happens when models are created and 'parented' before views
+    // This is performance unfriendly, but conversation can addToFolder multiple times
+    child_list_t::const_iterator iter;
+    for (iter = mChildren.begin(); iter != mChildren.end(); iter++)
+    {
+        if (child == *iter)
+        {
+            return;
+        }
+    }
+    LLFolderViewModelItemCommon::addChild(child);
+}
+
 void LLConversationItem::postEvent(const std::string& event_type, LLConversationItemSession* session, LLConversationItemParticipant* participant)
 {
 	LLUUID session_id = (session ? session->getUUID() : LLUUID());
diff --git a/indra/newview/llconversationmodel.h b/indra/newview/llconversationmodel.h
index 80385fad5f6..30c74818648 100644
--- a/indra/newview/llconversationmodel.h
+++ b/indra/newview/llconversationmodel.h
@@ -96,6 +96,7 @@ class LLConversationItem : public LLFolderViewModelItemCommon
 	virtual void buildContextMenu(LLMenuGL& menu, U32 flags) { }
 	virtual BOOL isUpToDate() const { return TRUE; }
 	virtual bool hasChildren() const { return FALSE; }
+    virtual void addChild(LLFolderViewModelItem* child);
 
 	virtual bool potentiallyVisible() { return true; }
 	virtual bool filter( LLFolderViewFilter& filter) { return false; }
-- 
GitLab