From cdbfdfc351a51f4fe0c264110cf68a59f0859f04 Mon Sep 17 00:00:00 2001
From: Dave Parks <davep@lindenlab.com>
Date: Thu, 11 Oct 2012 17:02:45 -0500
Subject: MAINT-1709 Factor out realloc

Reviewed by VoidPointer
---
 indra/llmath/lloctree.h | 52 +++++++++++++++++++++----------------------------
 1 file changed, 22 insertions(+), 30 deletions(-)

(limited to 'indra/llmath')

diff --git a/indra/llmath/lloctree.h b/indra/llmath/lloctree.h
index c3f6f7de2a..68d8110f1d 100644
--- a/indra/llmath/lloctree.h
+++ b/indra/llmath/lloctree.h
@@ -78,7 +78,7 @@ public:
 
 	typedef LLOctreeTraveler<T>									oct_traveler;
 	typedef LLTreeTraveler<T>									tree_traveler;
-	typedef LLPointer<T>*										element_list;
+	typedef std::vector<LLPointer<T>>							element_list;
 	typedef LLPointer<T>*										element_iter;
 	typedef const LLPointer<T>*									const_element_iter;
 	typedef typename std::vector<LLTreeListener<T>*>::iterator	tree_listener_iter;
@@ -106,8 +106,9 @@ public:
 	:	mParent((oct_node*)parent), 
 		mOctant(octant) 
 	{ 
-		mData = NULL;
-		mDataEnd = NULL;
+		//always keep a NULL terminated list to avoid out of bounds exceptions in debug builds
+		mData.push_back(NULL);
+		mDataEnd = &mData[0];
 
 		mCenter = center;
 		mSize = size;
@@ -133,9 +134,9 @@ public:
 			mData[i] = NULL;
 		}
 
-		free(mData);
-		mData = NULL;
-		mDataEnd = NULL;
+		mData.clear();
+		mData.push_back(NULL);
+		mDataEnd = &mData[0];
 
 		for (U32 i = 0; i < getChildCount(); i++)
 		{
@@ -239,9 +240,9 @@ public:
 	bool isEmpty() const							{ return mElementCount == 0; }
 	element_list& getData()							{ return mData; }
 	const element_list& getData() const				{ return mData; }
-	element_iter getDataBegin()						{ return mData; }
+	element_iter getDataBegin()						{ return &mData[0]; }
 	element_iter getDataEnd()						{ return mDataEnd; }
-	const_element_iter getDataBegin() const			{ return mData; }
+	const_element_iter getDataBegin() const			{ return &mData[0]; }
 	const_element_iter getDataEnd() const			{ return mDataEnd; }
 		
 	U32 getChildCount()	const						{ return mChildCount; }
@@ -321,14 +322,10 @@ public:
 			if ((getElementCount() < gOctreeMaxCapacity && contains(data->getBinRadius()) ||
 				(data->getBinRadius() > getSize()[0] &&	parent && parent->getElementCount() >= gOctreeMaxCapacity))) 
 			{ //it belongs here
+				mData.push_back(NULL);
+				mData[mElementCount] = data;
 				mElementCount++;
-				mData = (element_list) realloc(mData, sizeof(LLPointer<T>)*mElementCount);
-
-				//avoid unref on uninitialized memory
-				memset(mData+mElementCount-1, 0, sizeof(LLPointer<T>));
-
-				mData[mElementCount-1] = data;
-				mDataEnd = mData + mElementCount;
+				mDataEnd = &mData[mElementCount];
 				data->setBinIndex(mElementCount-1);
 				BaseType::insert(data);
 				return true;
@@ -364,14 +361,10 @@ public:
 
 				if( lt == 0x7 )
 				{
+					mData.push_back(NULL);
+					mData[mElementCount] = data;
 					mElementCount++;
-					mData = (element_list) realloc(mData, sizeof(LLPointer<T>)*mElementCount);
-
-					//avoid unref on uninitialized memory
-					memset(mData+mElementCount-1, 0, sizeof(LLPointer<T>));
-
-					mData[mElementCount-1] = data;
-					mDataEnd = mData + mElementCount;
+					mDataEnd = &mData[mElementCount];
 					data->setBinIndex(mElementCount-1);
 					BaseType::insert(data);
 					return true;
@@ -436,16 +429,15 @@ public:
 				mData[i]->setBinIndex(i);
 			}
 
-			mData[mElementCount] = NULL; //needed for unref
-			mData = (element_list) realloc(mData, sizeof(LLPointer<T>)*mElementCount);
-			mDataEnd = mData+mElementCount;
+			mData[mElementCount] = NULL;
+			mData.pop_back();
+			mDataEnd = &mData[mElementCount];
 		}
 		else
 		{
-			mData[0] = NULL; //needed for unref
-			free(mData);
-			mData = NULL;
-			mDataEnd = NULL;
+			mData.clear();
+			mData.push_back(NULL);
+			mDataEnd = &mData[0];
 		}
 
 		notifyRemoval(data);
@@ -491,7 +483,7 @@ public:
 		}
 
 		//node is now root
-		llwarns << "!!! OCTREE REMOVING FACE BY ADDRESS, SEVERE PERFORMANCE PENALTY |||" << llendl;
+		llwarns << "!!! OCTREE REMOVING ELEMENT BY ADDRESS, SEVERE PERFORMANCE PENALTY |||" << llendl;
 		node->removeByAddress(data);
 		llassert(data->getBinIndex() == -1);
 		return true;
-- 
cgit v1.2.3


From b8e14ad2b250ae8c4cae877035e38c485a841515 Mon Sep 17 00:00:00 2001
From: Dave Parks <davep@lindenlab.com>
Date: Fri, 26 Oct 2012 15:55:58 -0500
Subject: MAINT-1709 Fix for >> that should have been > >

---
 indra/llmath/lloctree.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

(limited to 'indra/llmath')

diff --git a/indra/llmath/lloctree.h b/indra/llmath/lloctree.h
index 68d8110f1d..4ac1e55cfc 100644
--- a/indra/llmath/lloctree.h
+++ b/indra/llmath/lloctree.h
@@ -78,7 +78,7 @@ public:
 
 	typedef LLOctreeTraveler<T>									oct_traveler;
 	typedef LLTreeTraveler<T>									tree_traveler;
-	typedef std::vector<LLPointer<T>>							element_list;
+	typedef std::vector<LLPointer<T> >							element_list;
 	typedef LLPointer<T>*										element_iter;
 	typedef const LLPointer<T>*									const_element_iter;
 	typedef typename std::vector<LLTreeListener<T>*>::iterator	tree_listener_iter;
-- 
cgit v1.2.3