From 1f672990e796ec55f7b684dbf46f939d1ab15607 Mon Sep 17 00:00:00 2001
From: Palmer Truelson <palmer@lindenlab.com>
Date: Fri, 12 Feb 2010 21:06:02 -0800
Subject: Backed out davep's optimization pass.  changeset 3c3685de430a

---
 indra/newview/llagent.cpp            |   3 -
 indra/newview/llappviewer.cpp        |   8 +-
 indra/newview/lldrawable.cpp         |   3 +
 indra/newview/llflexibleobject.cpp   |  15 +--
 indra/newview/llglsandbox.cpp        |  24 ++---
 indra/newview/llviewerobject.cpp     |   3 -
 indra/newview/llviewerobjectlist.cpp | 171 +++++++++++++++++------------------
 indra/newview/llviewerobjectlist.h   |  31 +++----
 indra/newview/llviewerwindow.cpp     |   4 +-
 indra/newview/llvoclouds.cpp         |   4 +-
 indra/newview/llvotextbubble.cpp     |   3 -
 indra/newview/llvovolume.cpp         |  17 +---
 indra/newview/llworld.cpp            |   3 -
 indra/newview/pipeline.cpp           |  64 ++++++++++---
 indra/newview/pipeline.h             |   5 +-
 15 files changed, 173 insertions(+), 185 deletions(-)

diff --git a/indra/newview/llagent.cpp b/indra/newview/llagent.cpp
index 9f2186f7f7..2354323a66 100644
--- a/indra/newview/llagent.cpp
+++ b/indra/newview/llagent.cpp
@@ -3017,9 +3017,6 @@ void LLAgent::endAnimationUpdateUI()
 //-----------------------------------------------------------------------------
 void LLAgent::updateCamera()
 {
-	static LLFastTimer::DeclareTimer ftm("Camera");
-	LLFastTimer t(ftm);
-
 	//Ventrella - changed camera_skyward to the new global "mCameraUpVector"
 	mCameraUpVector = LLVector3::z_axis;
 	//LLVector3	camera_skyward(0.f, 0.f, 1.f);
diff --git a/indra/newview/llappviewer.cpp b/indra/newview/llappviewer.cpp
index 9eb793783b..2d694eefd3 100644
--- a/indra/newview/llappviewer.cpp
+++ b/indra/newview/llappviewer.cpp
@@ -3599,15 +3599,13 @@ void LLAppViewer::idle()
 
 	{
 		// Handle pending gesture processing
-		static LLFastTimer::DeclareTimer ftm("Agent Position");
-		LLFastTimer t(ftm);
 		LLGestureManager::instance().update();
 
 		gAgent.updateAgentPosition(gFrameDTClamped, yaw, current_mouse.mX, current_mouse.mY);
 	}
 
 	{
-		LLFastTimer t(FTM_OBJECTLIST_UPDATE); 
+		LLFastTimer t(FTM_OBJECTLIST_UPDATE); // Actually "object update"
 		
         if (!(logoutRequestSent() && hasSavedFinalSnapshot()))
 		{
@@ -3641,8 +3639,6 @@ void LLAppViewer::idle()
 	//
 
 	{
-		static LLFastTimer::DeclareTimer ftm("HUD Effects");
-		LLFastTimer t(ftm);
 		LLSelectMgr::getInstance()->updateEffects();
 		LLHUDManager::getInstance()->cleanupEffects();
 		LLHUDManager::getInstance()->sendEffects();
@@ -3899,7 +3895,7 @@ void LLAppViewer::sendLogoutRequest()
 static F32 CheckMessagesMaxTime = CHECK_MESSAGES_DEFAULT_MAX_TIME;
 #endif
 
-static LLFastTimer::DeclareTimer FTM_IDLE_NETWORK("Idle Network");
+static LLFastTimer::DeclareTimer FTM_IDLE_NETWORK("Network");
 
 void LLAppViewer::idleNetwork()
 {
diff --git a/indra/newview/lldrawable.cpp b/indra/newview/lldrawable.cpp
index 244fed791f..d60330024a 100644
--- a/indra/newview/lldrawable.cpp
+++ b/indra/newview/lldrawable.cpp
@@ -386,6 +386,8 @@ void LLDrawable::makeActive()
 			mParent->makeActive();
 		}
 
+		gPipeline.setActive(this, TRUE);
+
 		//all child objects must also be active
 		llassert_always(mVObjp);
 		
@@ -432,6 +434,7 @@ void LLDrawable::makeStatic(BOOL warning_enabled)
 	if (isState(ACTIVE))
 	{
 		clearState(ACTIVE);
+		gPipeline.setActive(this, FALSE);
 
 		if (mParent.notNull() && mParent->isActive() && warning_enabled)
 		{
diff --git a/indra/newview/llflexibleobject.cpp b/indra/newview/llflexibleobject.cpp
index 561965d021..aea2de8e92 100644
--- a/indra/newview/llflexibleobject.cpp
+++ b/indra/newview/llflexibleobject.cpp
@@ -51,9 +51,6 @@
 
 /*static*/ F32 LLVolumeImplFlexible::sUpdateFactor = 1.0f;
 
-static LLFastTimer::DeclareTimer FTM_FLEXIBLE_REBUILD("Rebuild");
-static LLFastTimer::DeclareTimer FTM_DO_FLEXIBLE_UPDATE("Update");
-
 // LLFlexibleObjectData::pack/unpack now in llprimitive.cpp
 
 //-----------------------------------------------
@@ -197,6 +194,7 @@ void LLVolumeImplFlexible::remapSections(LLFlexibleObjectSection *source, S32 so
 	}
 }
 
+
 //-----------------------------------------------------------------------------
 void LLVolumeImplFlexible::setAttributesOfAllSections(LLVector3* inScale)
 {
@@ -365,7 +363,6 @@ inline S32 log2(S32 x)
 
 void LLVolumeImplFlexible::doFlexibleUpdate()
 {
-	LLFastTimer ftm(FTM_DO_FLEXIBLE_UPDATE);
 	LLVolume* volume = mVO->getVolume();
 	LLPath *path = &volume->getPath();
 	if (mSimulateRes == 0)
@@ -696,10 +693,7 @@ BOOL LLVolumeImplFlexible::doUpdateGeometry(LLDrawable *drawable)
 	}
 
 	volume->updateRelativeXform();
-	{
-		LLFastTimer t(FTM_DO_FLEXIBLE_UPDATE);
-		doFlexibleUpdate();
-	}
+	doFlexibleUpdate();
 	
 	// Object may have been rotated, which means it needs a rebuild.  See SL-47220
 	BOOL	rotated = FALSE;
@@ -716,10 +710,7 @@ BOOL LLVolumeImplFlexible::doUpdateGeometry(LLDrawable *drawable)
 		volume->regenFaces();
 		volume->mDrawable->setState(LLDrawable::REBUILD_VOLUME);
 		volume->dirtySpatialGroup();
-		{
-			LLFastTimer t(FTM_FLEXIBLE_REBUILD);
-			doFlexibleRebuild();
-		}
+		doFlexibleRebuild();
 		volume->genBBoxes(isVolumeGlobal());
 	}
 	else if (!mUpdated || rotated)
diff --git a/indra/newview/llglsandbox.cpp b/indra/newview/llglsandbox.cpp
index 8569e208eb..750a9d478f 100644
--- a/indra/newview/llglsandbox.cpp
+++ b/indra/newview/llglsandbox.cpp
@@ -897,21 +897,19 @@ void LLViewerObjectList::renderObjectBeacons()
 		S32 last_line_width = -1;
 		// gGL.begin(LLRender::LINES); // Always happens in (line_width != last_line_width)
 		
-		BOOL flush = FALSE;
-		for (std::vector<LLDebugBeacon>::iterator iter = mDebugBeacons.begin(); iter != mDebugBeacons.end(); ++iter)
+		for (S32 i = 0; i < mDebugBeacons.count(); i++)
 		{
-			const LLDebugBeacon &debug_beacon = *iter;
+			const LLDebugBeacon &debug_beacon = mDebugBeacons[i];
 			LLColor4 color = debug_beacon.mColor;
 			color.mV[3] *= 0.25f;
 			S32 line_width = debug_beacon.mLineWidth;
 			if (line_width != last_line_width)
 			{
-				if (flush)
+				if (i > 0)
 				{
 					gGL.end();
+					gGL.flush();
 				}
-				flush = TRUE;
-				gGL.flush();
 				glLineWidth( (F32)line_width );
 				last_line_width = line_width;
 				gGL.begin(LLRender::LINES);
@@ -938,20 +936,18 @@ void LLViewerObjectList::renderObjectBeacons()
 		S32 last_line_width = -1;
 		// gGL.begin(LLRender::LINES); // Always happens in (line_width != last_line_width)
 		
-		BOOL flush = FALSE;
-		for (std::vector<LLDebugBeacon>::iterator iter = mDebugBeacons.begin(); iter != mDebugBeacons.end(); ++iter)
+		for (S32 i = 0; i < mDebugBeacons.count(); i++)
 		{
-			const LLDebugBeacon &debug_beacon = *iter;
+			const LLDebugBeacon &debug_beacon = mDebugBeacons[i];
 
 			S32 line_width = debug_beacon.mLineWidth;
 			if (line_width != last_line_width)
 			{
-				if (flush)
+				if (i > 0)
 				{
 					gGL.end();
+					gGL.flush();
 				}
-				flush = TRUE;
-				gGL.flush();
 				glLineWidth( (F32)line_width );
 				last_line_width = line_width;
 				gGL.begin(LLRender::LINES);
@@ -973,9 +969,9 @@ void LLViewerObjectList::renderObjectBeacons()
 		gGL.flush();
 		glLineWidth(1.f);
 
-		for (std::vector<LLDebugBeacon>::iterator iter = mDebugBeacons.begin(); iter != mDebugBeacons.end(); ++iter)
+		for (S32 i = 0; i < mDebugBeacons.count(); i++)
 		{
-			LLDebugBeacon &debug_beacon = *iter;
+			LLDebugBeacon &debug_beacon = mDebugBeacons[i];
 			if (debug_beacon.mString == "")
 			{
 				continue;
diff --git a/indra/newview/llviewerobject.cpp b/indra/newview/llviewerobject.cpp
index 4fdfc37d6c..886f1d9ef5 100644
--- a/indra/newview/llviewerobject.cpp
+++ b/indra/newview/llviewerobject.cpp
@@ -2001,9 +2001,6 @@ BOOL LLViewerObject::isActive() const
 
 BOOL LLViewerObject::idleUpdate(LLAgent &agent, LLWorld &world, const F64 &time)
 {
-	static LLFastTimer::DeclareTimer ftm("Viewer Object");
-	LLFastTimer t(ftm);
-
 	if (mDead)
 	{
 		// It's dead.  Don't update it.
diff --git a/indra/newview/llviewerobjectlist.cpp b/indra/newview/llviewerobjectlist.cpp
index 6347090f71..96828ee1b6 100644
--- a/indra/newview/llviewerobjectlist.cpp
+++ b/indra/newview/llviewerobjectlist.cpp
@@ -93,7 +93,7 @@ extern LLPipeline	gPipeline;
 
 // Statics for object lookup tables.
 U32						LLViewerObjectList::sSimulatorMachineIndex = 1; // Not zero deliberately, to speed up index check.
-std::map<U64, U32>			LLViewerObjectList::sIPAndPortToIndex;
+LLMap<U64, U32>			LLViewerObjectList::sIPAndPortToIndex;
 std::map<U64, LLUUID>	LLViewerObjectList::sIndexAndLocalIDToUUID;
 
 LLViewerObjectList::LLViewerObjectList()
@@ -571,9 +571,10 @@ void LLViewerObjectList::processCachedObjectUpdate(LLMessageSystem *mesgsys,
 
 void LLViewerObjectList::dirtyAllObjectInventory()
 {
-	for (vobj_list_t::iterator iter = mObjects.begin(); iter != mObjects.end(); ++iter)
+	S32 count = mObjects.count();
+	for(S32 i = 0; i < count; ++i)
 	{
-		(*iter)->dirtyInventory();
+		mObjects[i]->dirtyInventory();
 	}
 }
 
@@ -586,14 +587,14 @@ void LLViewerObjectList::updateApparentAngles(LLAgent &agent)
 	S32 num_updates, max_value;
 	if (NUM_BINS - 1 == mCurBin)
 	{
-		num_updates = (S32) mObjects.size() - mCurLazyUpdateIndex;
-		max_value = (S32) mObjects.size();
+		num_updates = mObjects.count() - mCurLazyUpdateIndex;
+		max_value = mObjects.count();
 		gTextureList.setUpdateStats(TRUE);
 	}
 	else
 	{
-		num_updates = ((S32) mObjects.size() / NUM_BINS) + 1;
-		max_value = llmin((S32) mObjects.size(), mCurLazyUpdateIndex + num_updates);
+		num_updates = (mObjects.count() / NUM_BINS) + 1;
+		max_value = llmin(mObjects.count(), mCurLazyUpdateIndex + num_updates);
 	}
 
 
@@ -646,7 +647,7 @@ void LLViewerObjectList::updateApparentAngles(LLAgent &agent)
 	}
 
 	mCurLazyUpdateIndex = max_value;
-	if (mCurLazyUpdateIndex == mObjects.size())
+	if (mCurLazyUpdateIndex == mObjects.count())
 	{
 		mCurLazyUpdateIndex = 0;
 	}
@@ -693,26 +694,20 @@ void LLViewerObjectList::update(LLAgent &agent, LLWorld &world)
 	
 	// Make a copy of the list in case something in idleUpdate() messes with it
 	std::vector<LLViewerObject*> idle_list;
-	
-	static LLFastTimer::DeclareTimer idle_copy("Idle Copy");
+	idle_list.reserve( mActiveObjects.size() );
 
+ 	for (std::set<LLPointer<LLViewerObject> >::iterator active_iter = mActiveObjects.begin();
+		active_iter != mActiveObjects.end(); active_iter++)
 	{
-		LLFastTimer t(idle_copy);
-		idle_list.reserve( mActiveObjects.size() );
-
- 		for (std::set<LLPointer<LLViewerObject> >::iterator active_iter = mActiveObjects.begin();
-			active_iter != mActiveObjects.end(); active_iter++)
+		objectp = *active_iter;
+		if (objectp)
 		{
-			objectp = *active_iter;
-			if (objectp)
-			{
-				idle_list.push_back( objectp );
-			}
-			else
-			{	// There shouldn't be any NULL pointers in the list, but they have caused
-				// crashes before.  This may be idleUpdate() messing with the list.
-				llwarns << "LLViewerObjectList::update has a NULL objectp" << llendl;
-			}
+			idle_list.push_back( objectp );
+		}
+		else
+		{	// There shouldn't be any NULL pointers in the list, but they have caused
+			// crashes before.  This may be idleUpdate() messing with the list.
+			llwarns << "LLViewerObjectList::update has a NULL objectp" << llendl;
 		}
 	}
 
@@ -812,7 +807,7 @@ void LLViewerObjectList::update(LLAgent &agent, LLWorld &world)
 	}
 	*/
 
-	LLViewerStats::getInstance()->mNumObjectsStat.addValue((S32) mObjects.size());
+	LLViewerStats::getInstance()->mNumObjectsStat.addValue(mObjects.count());
 	LLViewerStats::getInstance()->mNumActiveObjectsStat.addValue(num_active_objects);
 	LLViewerStats::getInstance()->mNumSizeCulledStat.addValue(mNumSizeCulled);
 	LLViewerStats::getInstance()->mNumVisCulledStat.addValue(mNumVisCulled);
@@ -820,9 +815,9 @@ void LLViewerObjectList::update(LLAgent &agent, LLWorld &world)
 
 void LLViewerObjectList::clearDebugText()
 {
-	for (vobj_list_t::iterator iter = mObjects.begin(); iter != mObjects.end(); ++iter)
+	for (S32 i = 0; i < mObjects.count(); i++)
 	{
-		(*iter)->setDebugText("");
+		mObjects[i]->setDebugText("");
 	}
 }
 
@@ -861,7 +856,7 @@ void LLViewerObjectList::cleanupReferences(LLViewerObject *objectp)
 
 	if (objectp->isOnMap())
 	{
-		removeFromMap(objectp);
+		mMapObjects.removeObj(objectp);
 	}
 
 	// Don't clean up mObject references, these will be cleaned up more efficiently later!
@@ -918,10 +913,10 @@ void LLViewerObjectList::killObjects(LLViewerRegion *regionp)
 {
 	LLViewerObject *objectp;
 
-	
-	for (vobj_list_t::iterator iter = mObjects.begin(); iter != mObjects.end(); ++iter)
+	S32 i;
+	for (i = 0; i < mObjects.count(); i++)
 	{
-		objectp = *iter;
+		objectp = mObjects[i];
 		
 		if (objectp->mRegionp == regionp)
 		{
@@ -938,9 +933,10 @@ void LLViewerObjectList::killAllObjects()
 	// Used only on global destruction.
 	LLViewerObject *objectp;
 
-	for (vobj_list_t::iterator iter = mObjects.begin(); iter != mObjects.end(); ++iter)
+	for (S32 i = 0; i < mObjects.count(); i++)
 	{
-		objectp = *iter;
+		objectp = mObjects[i];
+		
 		killObject(objectp);
 		llassert(objectp->isDead());
 	}
@@ -949,7 +945,7 @@ void LLViewerObjectList::killAllObjects()
 
 	if(!mObjects.empty())
 	{
-		llwarns << "LLViewerObjectList::killAllObjects still has entries in mObjects: " << mObjects.size() << llendl;
+		llwarns << "LLViewerObjectList::killAllObjects still has entries in mObjects: " << mObjects.count() << llendl;
 		mObjects.clear();
 	}
 
@@ -974,15 +970,16 @@ void LLViewerObjectList::cleanDeadObjects(BOOL use_timer)
 		return;
 	}
 
+	S32 i = 0;
 	S32 num_removed = 0;
 	LLViewerObject *objectp;
-	for (vobj_list_t::iterator iter = mObjects.begin(); iter != mObjects.end(); )
+	while (i < mObjects.count())
 	{
 		// Scan for all of the dead objects and remove any "global" references to them.
-		objectp = *iter;
+		objectp = mObjects[i];
 		if (objectp->isDead())
 		{
-			iter = mObjects.erase(iter);
+			mObjects.remove(i);
 			num_removed++;
 
 			if (num_removed == mNumDeadObjects)
@@ -993,7 +990,8 @@ void LLViewerObjectList::cleanDeadObjects(BOOL use_timer)
 		}
 		else
 		{
-			++iter;
+			// iterate, this isn't a dead object.
+			i++;
 		}
 	}
 
@@ -1043,11 +1041,12 @@ void LLViewerObjectList::shiftObjects(const LLVector3 &offset)
 	}
 
 	LLViewerObject *objectp;
-	for (vobj_list_t::iterator iter = mObjects.begin(); iter != mObjects.end(); ++iter)
+	S32 i;
+	for (i = 0; i < mObjects.count(); i++)
 	{
-		objectp = *iter;
+		objectp = getObject(i);
 		// There could be dead objects on the object list, so don't update stuff if the object is dead.
-		if (!objectp->isDead())
+		if (objectp)
 		{
 			objectp->updatePositionCaches();
 
@@ -1077,9 +1076,9 @@ void LLViewerObjectList::renderObjectsForMap(LLNetMap &netmap)
 
 	F32 max_radius = gSavedSettings.getF32("MiniMapPrimMaxRadius");
 
-	for (vobj_list_t::iterator iter = mMapObjects.begin(); iter != mMapObjects.end(); ++iter)
+	for (S32 i = 0; i < mMapObjects.count(); i++)
 	{
-		LLViewerObject* objectp = *iter;
+		LLViewerObject* objectp = mMapObjects[i];
 		if (!objectp->getRegion() || objectp->isOrphaned() || objectp->isAttachment())
 		{
 			continue;
@@ -1145,14 +1144,21 @@ void LLViewerObjectList::renderObjectBounds(const LLVector3 &center)
 {
 }
 
+void LLViewerObjectList::renderObjectsForSelect(LLCamera &camera, const LLRect& screen_rect, BOOL pick_parcel_wall, BOOL render_transparent)
+{
+	generatePickList(camera);
+	renderPickList(screen_rect, pick_parcel_wall, render_transparent);
+}
+
 void LLViewerObjectList::generatePickList(LLCamera &camera)
 {
 		LLViewerObject *objectp;
 		S32 i;
 		// Reset all of the GL names to zero.
-		for (vobj_list_t::iterator iter = mObjects.begin(); iter != mObjects.end(); ++iter)
+		for (i = 0; i < mObjects.count(); i++)
 		{
-			(*iter)->mGLName = 0;
+			objectp = mObjects[i];
+			objectp->mGLName = 0;
 		}
 
 		mSelectPickList.clear();
@@ -1315,19 +1321,17 @@ void LLViewerObjectList::addDebugBeacon(const LLVector3 &pos_agent,
 										const LLColor4 &text_color,
 										S32 line_width)
 {
-	LLDebugBeacon beacon;
-	beacon.mPositionAgent = pos_agent;
-	beacon.mString = string;
-	beacon.mColor = color;
-	beacon.mTextColor = text_color;
-	beacon.mLineWidth = line_width;
-
-	mDebugBeacons.push_back(beacon);
+	LLDebugBeacon *beaconp = mDebugBeacons.reserve_block(1);
+	beaconp->mPositionAgent = pos_agent;
+	beaconp->mString = string;
+	beaconp->mColor = color;
+	beaconp->mTextColor = text_color;
+	beaconp->mLineWidth = line_width;
 }
 
 void LLViewerObjectList::resetObjectBeacons()
 {
-	mDebugBeacons.clear();
+	mDebugBeacons.reset();
 }
 
 LLViewerObject *LLViewerObjectList::createObjectViewer(const LLPCode pcode, LLViewerRegion *regionp)
@@ -1345,7 +1349,7 @@ LLViewerObject *LLViewerObjectList::createObjectViewer(const LLPCode pcode, LLVi
 
 	mUUIDObjectMap[fullid] = objectp;
 
-	mObjects.push_back(objectp);
+	mObjects.put(objectp);
 
 	updateActive(objectp);
 
@@ -1384,7 +1388,7 @@ LLViewerObject *LLViewerObjectList::createObject(const LLPCode pcode, LLViewerRe
 					gMessageSystem->getSenderIP(),
 					gMessageSystem->getSenderPort());
 
-	mObjects.push_back(objectp);
+	mObjects.put(objectp);
 
 	updateActive(objectp);
 
@@ -1407,11 +1411,11 @@ LLViewerObject *LLViewerObjectList::replaceObject(const LLUUID &id, const LLPCod
 S32 LLViewerObjectList::findReferences(LLDrawable *drawablep) const
 {
 	LLViewerObject *objectp;
+	S32 i;
 	S32 num_refs = 0;
-	
-	for (vobj_list_t::const_iterator iter = mObjects.begin(); iter != mObjects.end(); ++iter)
+	for (i = 0; i < mObjects.count(); i++)
 	{
-		objectp = *iter;
+		objectp = mObjects[i];
 		if (objectp->mDrawable.notNull())
 		{
 			num_refs += objectp->mDrawable->findReferences(drawablep);
@@ -1456,15 +1460,15 @@ void LLViewerObjectList::orphanize(LLViewerObject *childp, U32 parent_id, U32 ip
 	// Unknown parent, add to orpaned child list
 	U64 parent_info = getIndex(parent_id, ip, port);
 
-	if (std::find(mOrphanParents.begin(), mOrphanParents.end(), parent_info) == mOrphanParents.end())
+	if (-1 == mOrphanParents.find(parent_info))
 	{
-		mOrphanParents.push_back(parent_info);
+		mOrphanParents.put(parent_info);
 	}
 
 	LLViewerObjectList::OrphanInfo oi(parent_info, childp->mID);
-	if (std::find(mOrphanChildren.begin(), mOrphanChildren.end(), oi) == mOrphanChildren.end())
+	if (-1 == mOrphanChildren.find(oi))
 	{
-		mOrphanChildren.push_back(oi);
+		mOrphanChildren.put(oi);
 		mNumOrphans++;
 	}
 }
@@ -1487,29 +1491,28 @@ void LLViewerObjectList::findOrphans(LLViewerObject* objectp, U32 ip, U32 port)
 	// See if we are a parent of an orphan.
 	// Note:  This code is fairly inefficient but it should happen very rarely.
 	// It can be sped up if this is somehow a performance issue...
-	if (mOrphanParents.empty())
+	if (0 == mOrphanParents.count())
 	{
 		// no known orphan parents
 		return;
 	}
-	if (std::find(mOrphanParents.begin(), mOrphanParents.end(), getIndex(objectp->mLocalID, ip, port)) == mOrphanParents.end())
+	if (-1 == mOrphanParents.find(getIndex(objectp->mLocalID, ip, port)))
 	{
 		// did not find objectp in OrphanParent list
 		return;
 	}
 
+	S32 i;
 	U64 parent_info = getIndex(objectp->mLocalID, ip, port);
 	BOOL orphans_found = FALSE;
 	// Iterate through the orphan list, and set parents of matching children.
-
-	for (std::vector<OrphanInfo>::iterator iter = mOrphanChildren.begin(); iter != mOrphanChildren.end(); )
-	{	
-		if (iter->mParentInfo != parent_info)
+	for (i = 0; i < mOrphanChildren.count(); i++)
+	{
+		if (mOrphanChildren[i].mParentInfo != parent_info)
 		{
-			++iter;
 			continue;
 		}
-		LLViewerObject *childp = findObject(iter->mChildInfo);
+		LLViewerObject *childp = findObject(mOrphanChildren[i].mChildInfo);
 		if (childp)
 		{
 			if (childp == objectp)
@@ -1543,35 +1546,29 @@ void LLViewerObjectList::findOrphans(LLViewerObject* objectp, U32 ip, U32 port)
 
 			objectp->addChild(childp);
 			orphans_found = TRUE;
-			++iter;
 		}
 		else
 		{
 			llinfos << "Missing orphan child, removing from list" << llendl;
-
-			iter = mOrphanChildren.erase(iter);
+			mOrphanChildren.remove(i);
+			i--;
 		}
 	}
 
 	// Remove orphan parent and children from lists now that they've been found
+	mOrphanParents.remove(mOrphanParents.find(parent_info));
+
+	i = 0;
+	while (i < mOrphanChildren.count())
 	{
-		std::vector<U64>::iterator iter = std::find(mOrphanParents.begin(), mOrphanParents.end(), parent_info);
-		if (iter != mOrphanParents.end())
-		{
-			mOrphanParents.erase(iter);
-		}
-	}
-	
-	for (std::vector<OrphanInfo>::iterator iter = mOrphanChildren.begin(); iter != mOrphanChildren.end(); )
-	{
-		if (iter->mParentInfo == parent_info)
+		if (mOrphanChildren[i].mParentInfo == parent_info)
 		{
-			iter = mOrphanChildren.erase(iter);
+			mOrphanChildren.remove(i);
 			mNumOrphans--;
 		}
 		else
 		{
-			++iter;
+			i++;
 		}
 	}
 
diff --git a/indra/newview/llviewerobjectlist.h b/indra/newview/llviewerobjectlist.h
index 8d3d2c4b44..ace5c5038e 100644
--- a/indra/newview/llviewerobjectlist.h
+++ b/indra/newview/llviewerobjectlist.h
@@ -38,6 +38,8 @@
 
 // common includes
 #include "llstat.h"
+#include "lldarrayptr.h"
+#include "llmap.h"			// *TODO: switch to std::map
 #include "llstring.h"
 
 // project includes
@@ -48,7 +50,7 @@ class LLNetMap;
 class LLDebugBeacon;
 
 const U32 CLOSE_BIN_SIZE = 10;
-const U32 NUM_BINS = 128;
+const U32 NUM_BINS = 16;
 
 // GL name = position in object list + GL_NAME_INDEX_OFFSET so that
 // we can have special numbers like zero.
@@ -109,12 +111,13 @@ public:
 	void updateAvatarVisibility();
 
 	// Selection related stuff
+	void renderObjectsForSelect(LLCamera &camera, const LLRect& screen_rect, BOOL pick_parcel_wall = FALSE, BOOL render_transparent = TRUE);
 	void generatePickList(LLCamera &camera);
 	void renderPickList(const LLRect& screen_rect, BOOL pick_parcel_wall, BOOL render_transparent);
 
 	LLViewerObject *getSelectedObject(const U32 object_id);
 
-	inline S32 getNumObjects() { return (S32) mObjects.size(); }
+	inline S32 getNumObjects() { return mObjects.count(); }
 
 	void addToMap(LLViewerObject *objectp);
 	void removeFromMap(LLViewerObject *objectp);
@@ -128,7 +131,7 @@ public:
 
 	S32 findReferences(LLDrawable *drawablep) const; // Find references to drawable in all objects, and return value.
 
-	S32 getOrphanParentCount() const { return (S32) mOrphanParents.size(); }
+	S32 getOrphanParentCount() const { return mOrphanParents.count(); }
 	S32 getOrphanCount() const { return mNumOrphans; }
 	void orphanize(LLViewerObject *childp, U32 parent_id, U32 ip, U32 port);
 	void findOrphans(LLViewerObject* objectp, U32 ip, U32 port);
@@ -176,28 +179,26 @@ public:
 	S32 mNumUnknownKills;
 	S32 mNumDeadObjects;
 protected:
-	std::vector<U64>	mOrphanParents;	// LocalID/ip,port of orphaned objects
-	std::vector<OrphanInfo> mOrphanChildren;	// UUID's of orphaned objects
+	LLDynamicArray<U64>	mOrphanParents;	// LocalID/ip,port of orphaned objects
+	LLDynamicArray<OrphanInfo> mOrphanChildren;	// UUID's of orphaned objects
 	S32 mNumOrphans;
 
-	typedef std::vector<LLPointer<LLViewerObject> > vobj_list_t;
-
-	vobj_list_t mObjects;
+	LLDynamicArrayPtr<LLPointer<LLViewerObject>, 256> mObjects;
 	std::set<LLPointer<LLViewerObject> > mActiveObjects;
 
-	vobj_list_t mMapObjects;
+	LLDynamicArrayPtr<LLPointer<LLViewerObject> > mMapObjects;
 
 	typedef std::map<LLUUID, LLPointer<LLViewerObject> > vo_map;
 	vo_map mDeadObjects;	// Need to keep multiple entries per UUID
 
 	std::map<LLUUID, LLPointer<LLViewerObject> > mUUIDObjectMap;
 
-	std::vector<LLDebugBeacon> mDebugBeacons;
+	LLDynamicArray<LLDebugBeacon> mDebugBeacons;
 
 	S32 mCurLazyUpdateIndex;
 
 	static U32 sSimulatorMachineIndex;
-	static std::map<U64, U32> sIPAndPortToIndex;
+	static LLMap<U64, U32> sIPAndPortToIndex;
 
 	static std::map<U64, LLUUID> sIndexAndLocalIDToUUID;
 
@@ -259,16 +260,12 @@ inline LLViewerObject *LLViewerObjectList::getObject(const S32 index)
 
 inline void LLViewerObjectList::addToMap(LLViewerObject *objectp)
 {
-	mMapObjects.push_back(objectp);
+	mMapObjects.put(objectp);
 }
 
 inline void LLViewerObjectList::removeFromMap(LLViewerObject *objectp)
 {
-	std::vector<LLPointer<LLViewerObject> >::iterator iter = std::find(mMapObjects.begin(), mMapObjects.end(), objectp);
-	if (iter != mMapObjects.end())
-	{
-		mMapObjects.erase(iter);
-	}
+	mMapObjects.removeObj(objectp);
 }
 
 
diff --git a/indra/newview/llviewerwindow.cpp b/indra/newview/llviewerwindow.cpp
index de4317b2de..cd6b9e2c50 100644
--- a/indra/newview/llviewerwindow.cpp
+++ b/indra/newview/llviewerwindow.cpp
@@ -2316,9 +2316,6 @@ void append_xui_tooltip(LLView* viewp, LLToolTip::Params& params)
 // event processing.
 void LLViewerWindow::updateUI()
 {
-	static LLFastTimer::DeclareTimer ftm("Update UI");
-	LLFastTimer t(ftm);
-
 	static std::string last_handle_msg;
 
 	// animate layout stacks so we have up to date rect for world view
@@ -2898,6 +2895,7 @@ void LLViewerWindow::saveLastMouse(const LLCoordGL &point)
 // Must be called after displayObjects is called, which sets the mGLName parameter
 // NOTE: This function gets called 3 times:
 //  render_ui_3d: 			FALSE, FALSE, TRUE
+//  renderObjectsForSelect:	TRUE, pick_parcel_wall, FALSE
 //  render_hud_elements:	FALSE, FALSE, FALSE
 void LLViewerWindow::renderSelections( BOOL for_gl_pick, BOOL pick_parcel_walls, BOOL for_hud )
 {
diff --git a/indra/newview/llvoclouds.cpp b/indra/newview/llvoclouds.cpp
index 5153cef709..177cb16c50 100644
--- a/indra/newview/llvoclouds.cpp
+++ b/indra/newview/llvoclouds.cpp
@@ -77,11 +77,9 @@ BOOL LLVOClouds::isActive() const
 	return TRUE;
 }
 
+
 BOOL LLVOClouds::idleUpdate(LLAgent &agent, LLWorld &world, const F64 &time)
 {
-	static LLFastTimer::DeclareTimer ftm("Idle Clouds");
-	LLFastTimer t(ftm);
-
 	if (!(gPipeline.hasRenderType(LLPipeline::RENDER_TYPE_CLOUDS)))
 	{
 		return TRUE;
diff --git a/indra/newview/llvotextbubble.cpp b/indra/newview/llvotextbubble.cpp
index 428ef20006..75beab519e 100644
--- a/indra/newview/llvotextbubble.cpp
+++ b/indra/newview/llvotextbubble.cpp
@@ -84,9 +84,6 @@ BOOL LLVOTextBubble::isActive() const
 
 BOOL LLVOTextBubble::idleUpdate(LLAgent &agent, LLWorld	&world, const F64 &time)
 {
-	static LLFastTimer::DeclareTimer ftm("Text Bubble");
-	LLFastTimer t(ftm);
-
 	F32 dt = mUpdateTimer.getElapsedTimeF32();
 	// Die after a few seconds.
 	if (dt > 1.5f)
diff --git a/indra/newview/llvovolume.cpp b/indra/newview/llvovolume.cpp
index 3cdf485d7d..bfe38c14ba 100644
--- a/indra/newview/llvovolume.cpp
+++ b/indra/newview/llvovolume.cpp
@@ -597,9 +597,6 @@ BOOL LLVOVolume::idleUpdate(LLAgent &agent, LLWorld &world, const F64 &time)
 {
 	LLViewerObject::idleUpdate(agent, world, time);
 
-	static LLFastTimer::DeclareTimer ftm("Volume");
-	LLFastTimer t(ftm);
-
 	if (mDead || mDrawable.isNull())
 	{
 		return TRUE;
@@ -621,18 +618,6 @@ BOOL LLVOVolume::idleUpdate(LLAgent &agent, LLWorld &world, const F64 &time)
 		mVolumeImpl->doIdleUpdate(agent, world, time);
 	}
 
-	const S32 MAX_ACTIVE_OBJECT_QUIET_FRAMES = 40;
-
-	if (mDrawable->isActive())
-	{
-		if (mDrawable->isRoot() && 
-			mDrawable->mQuietCount++ > MAX_ACTIVE_OBJECT_QUIET_FRAMES && 
-			(!mDrawable->getParent() || !mDrawable->getParent()->isActive()))
-		{
-			mDrawable->makeStatic();
-		}
-	}
-
 	return TRUE;
 }
 
@@ -1050,7 +1035,7 @@ BOOL LLVOVolume::calcLOD()
 	S32 cur_detail = 0;
 	
 	F32 radius = getVolume()->mLODScaleBias.scaledVec(getScale()).length();
-	F32 distance = mDrawable->mDistanceWRTCamera; //llmin(mDrawable->mDistanceWRTCamera, MAX_LOD_DISTANCE);
+	F32 distance = llmin(mDrawable->mDistanceWRTCamera, MAX_LOD_DISTANCE);
 	distance *= sDistanceFactor;
 			
 	F32 rampDist = LLVOVolume::sLODFactor * 2;
diff --git a/indra/newview/llworld.cpp b/indra/newview/llworld.cpp
index d7e5b464a6..118d7f8d08 100644
--- a/indra/newview/llworld.cpp
+++ b/indra/newview/llworld.cpp
@@ -657,9 +657,6 @@ void LLWorld::updateParticles()
 
 void LLWorld::updateClouds(const F32 dt)
 {
-	static LLFastTimer::DeclareTimer ftm("World Clouds");
-	LLFastTimer t(ftm);
-
 	if (gSavedSettings.getBOOL("FreezeTime") ||
 		!gSavedSettings.getBOOL("SkyUseClassicClouds"))
 	{
diff --git a/indra/newview/pipeline.cpp b/indra/newview/pipeline.cpp
index d5f87b73fe..4f4fc83819 100644
--- a/indra/newview/pipeline.cpp
+++ b/indra/newview/pipeline.cpp
@@ -116,6 +116,7 @@ const F32 BACKLIGHT_DAY_MAGNITUDE_AVATAR = 0.2f;
 const F32 BACKLIGHT_NIGHT_MAGNITUDE_AVATAR = 0.1f;
 const F32 BACKLIGHT_DAY_MAGNITUDE_OBJECT = 0.1f;
 const F32 BACKLIGHT_NIGHT_MAGNITUDE_OBJECT = 0.08f;
+const S32 MAX_ACTIVE_OBJECT_QUIET_FRAMES = 40;
 const S32 MAX_OFFSCREEN_GEOMETRY_CHANGES_PER_FRAME = 10;
 const U32 REFLECTION_MAP_RES = 128;
 
@@ -1410,26 +1411,38 @@ void LLPipeline::updateMove()
 
 	assertInitialized();
 
+	for (LLDrawable::drawable_set_t::iterator iter = mRetexturedList.begin();
+		 iter != mRetexturedList.end(); ++iter)
 	{
-		static LLFastTimer::DeclareTimer ftm("Retexture");
-		LLFastTimer t(ftm);
-
-		for (LLDrawable::drawable_set_t::iterator iter = mRetexturedList.begin();
-			 iter != mRetexturedList.end(); ++iter)
+		LLDrawable* drawablep = *iter;
+		if (drawablep && !drawablep->isDead())
 		{
-			LLDrawable* drawablep = *iter;
-			if (drawablep && !drawablep->isDead())
-			{
-				drawablep->updateTexture();
-			}
+			drawablep->updateTexture();
 		}
-		mRetexturedList.clear();
 	}
+	mRetexturedList.clear();
 
+	updateMovedList(mMovedList);
+
+	for (LLDrawable::drawable_set_t::iterator iter = mActiveQ.begin();
+		 iter != mActiveQ.end(); )
 	{
-		static LLFastTimer::DeclareTimer ftm("Moved List");
-		LLFastTimer t(ftm);
-		updateMovedList(mMovedList);
+		LLDrawable::drawable_set_t::iterator curiter = iter++;
+		LLDrawable* drawablep = *curiter;
+		if (drawablep && !drawablep->isDead()) 
+		{
+			if (drawablep->isRoot() && 
+				drawablep->mQuietCount++ > MAX_ACTIVE_OBJECT_QUIET_FRAMES && 
+				(!drawablep->getParent() || !drawablep->getParent()->isActive()))
+			{
+				drawablep->makeStatic(); // removes drawable and its children from mActiveQ
+				iter = mActiveQ.upper_bound(drawablep); // next valid entry
+			}
+		}
+		else
+		{
+			mActiveQ.erase(curiter);
+		}
 	}
 
 	//balance octrees
@@ -3045,6 +3058,12 @@ void LLPipeline::renderGeom(LLCamera& camera, BOOL forceVBOUpdate)
 		}
 	}
 
+	if (gPipeline.hasRenderDebugMask(LLPipeline::RENDER_DEBUG_PICKING))
+	{
+		LLAppViewer::instance()->pingMainloopTimeout("Pipeline:RenderForSelect");
+		gObjectList.renderObjectsForSelect(camera, gViewerWindow->getWindowRectScaled());
+	}
+	else
 	{
 		LLFastTimer t(FTM_POOLS);
 		
@@ -4778,6 +4797,10 @@ void LLPipeline::findReferences(LLDrawable *drawablep)
 		llinfos << "In mRetexturedList" << llendl;
 	}
 	
+	if (mActiveQ.find(drawablep) != mActiveQ.end())
+	{
+		llinfos << "In mActiveQ" << llendl;
+	}
 	if (std::find(mBuildQ1.begin(), mBuildQ1.end(), drawablep) != mBuildQ1.end())
 	{
 		llinfos << "In mBuildQ1" << llendl;
@@ -4934,6 +4957,19 @@ void LLPipeline::setLight(LLDrawable *drawablep, BOOL is_light)
 	}
 }
 
+void LLPipeline::setActive(LLDrawable *drawablep, BOOL active)
+{
+	assertInitialized();
+	if (active)
+	{
+		mActiveQ.insert(drawablep);
+	}
+	else
+	{
+		mActiveQ.erase(drawablep);
+	}
+}
+
 //static
 void LLPipeline::toggleRenderType(U32 type)
 {
diff --git a/indra/newview/pipeline.h b/indra/newview/pipeline.h
index c5285943e8..67004a5f2d 100644
--- a/indra/newview/pipeline.h
+++ b/indra/newview/pipeline.h
@@ -270,7 +270,8 @@ public:
 	void shiftObjects(const LLVector3 &offset);
 
 	void setLight(LLDrawable *drawablep, BOOL is_light);
-	
+	void setActive(LLDrawable *drawablep, BOOL active);
+
 	BOOL hasRenderBatches(const U32 type) const;
 	LLCullResult::drawinfo_list_t::iterator beginRenderMap(U32 type);
 	LLCullResult::drawinfo_list_t::iterator endRenderMap(U32 type);
@@ -588,6 +589,8 @@ protected:
 
 	LLViewerObject::vobj_list_t		mCreateQ;
 		
+	LLDrawable::drawable_set_t		mActiveQ;
+	
 	LLDrawable::drawable_set_t		mRetexturedList;
 
 	class HighlightItem
-- 
cgit v1.2.3