diff options
author | Dave Parks <davep@lindenlab.com> | 2012-10-11 17:02:45 -0500 |
---|---|---|
committer | Dave Parks <davep@lindenlab.com> | 2012-10-11 17:02:45 -0500 |
commit | cdbfdfc351a51f4fe0c264110cf68a59f0859f04 (patch) | |
tree | a8944dacc7f9fc07eaad0698684c559749660967 /indra | |
parent | 1743e6a81330824021667000f8acdd6cf64dbf1b (diff) |
MAINT-1709 Factor out realloc
Reviewed by VoidPointer
Diffstat (limited to 'indra')
-rw-r--r-- | indra/llmath/lloctree.h | 52 | ||||
-rw-r--r-- | indra/newview/llspatialpartition.cpp | 98 | ||||
-rw-r--r-- | indra/newview/llspatialpartition.h | 10 |
3 files changed, 80 insertions, 80 deletions
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; diff --git a/indra/newview/llspatialpartition.cpp b/indra/newview/llspatialpartition.cpp index 7264ba3cab..3bb8e60787 100644 --- a/indra/newview/llspatialpartition.cpp +++ b/indra/newview/llspatialpartition.cpp @@ -4713,55 +4713,63 @@ LLCullResult::LLCullResult() mVisibleListAllocated = 0; mVisibleBridgeAllocated = 0; - mVisibleGroups = NULL; - mVisibleGroupsEnd = NULL; - mAlphaGroups = NULL; - mAlphaGroupsEnd = NULL; - mOcclusionGroups = NULL; - mOcclusionGroupsEnd = NULL; - mDrawableGroups = NULL; - mDrawableGroupsEnd = NULL; - mVisibleList = NULL; - mVisibleListEnd = NULL; - mVisibleBridge = NULL; - mVisibleBridgeEnd = NULL; + mVisibleGroups.clear(); + mVisibleGroups.push_back(NULL); + mVisibleGroupsEnd = &mVisibleGroups[0]; + mAlphaGroups.clear(); + mAlphaGroups.push_back(NULL); + mAlphaGroupsEnd = &mAlphaGroups[0]; + mOcclusionGroups.clear(); + mOcclusionGroups.push_back(NULL); + mOcclusionGroupsEnd = &mOcclusionGroups[0]; + mDrawableGroups.clear(); + mDrawableGroups.push_back(NULL); + mDrawableGroupsEnd = &mDrawableGroups[0]; + mVisibleList.clear(); + mVisibleList.push_back(NULL); + mVisibleListEnd = &mVisibleList[0]; + mVisibleBridge.clear(); + mVisibleBridge.push_back(NULL); + mVisibleBridgeEnd = &mVisibleBridge[0]; for (U32 i = 0; i < LLRenderPass::NUM_RENDER_TYPES; i++) { - mRenderMap[i] = NULL; - mRenderMapEnd[i] = NULL; + mRenderMap[i].clear(); + mRenderMap[i].push_back(NULL); + mRenderMapEnd[i] = &mRenderMap[i][0]; mRenderMapAllocated[i] = 0; } clear(); } -void LLCullResult::pushBack(void**& head, U32& count, void* val) +template <class T, class V> +void LLCullResult::pushBack(T& head, U32& count, V* val) { + head[count] = val; + head.push_back(NULL); count++; - head = (void**) realloc((void*) head, sizeof(void*) * count); - head[count-1] = val; } void LLCullResult::clear() { mVisibleGroupsSize = 0; - mVisibleGroupsEnd = mVisibleGroups; + mVisibleGroupsEnd = &mVisibleGroups[0]; mAlphaGroupsSize = 0; - mAlphaGroupsEnd = mAlphaGroups; + mAlphaGroupsEnd = &mAlphaGroups[0]; mOcclusionGroupsSize = 0; - mOcclusionGroupsEnd = mOcclusionGroups; + mOcclusionGroupsEnd = &mOcclusionGroups[0]; mDrawableGroupsSize = 0; - mDrawableGroupsEnd = mDrawableGroups; + mDrawableGroupsEnd = &mDrawableGroups[0]; mVisibleListSize = 0; - mVisibleListEnd = mVisibleList; + mVisibleListEnd = &mVisibleList[0]; mVisibleBridgeSize = 0; - mVisibleBridgeEnd = mVisibleBridge; + mVisibleBridgeEnd = &mVisibleBridge[0]; for (U32 i = 0; i < LLRenderPass::NUM_RENDER_TYPES; i++) @@ -4771,13 +4779,13 @@ void LLCullResult::clear() mRenderMap[i][j] = 0; } mRenderMapSize[i] = 0; - mRenderMapEnd[i] = mRenderMap[i]; + mRenderMapEnd[i] = &(mRenderMap[i][0]); } } LLCullResult::sg_iterator LLCullResult::beginVisibleGroups() { - return mVisibleGroups; + return &mVisibleGroups[0]; } LLCullResult::sg_iterator LLCullResult::endVisibleGroups() @@ -4787,7 +4795,7 @@ LLCullResult::sg_iterator LLCullResult::endVisibleGroups() LLCullResult::sg_iterator LLCullResult::beginAlphaGroups() { - return mAlphaGroups; + return &mAlphaGroups[0]; } LLCullResult::sg_iterator LLCullResult::endAlphaGroups() @@ -4797,7 +4805,7 @@ LLCullResult::sg_iterator LLCullResult::endAlphaGroups() LLCullResult::sg_iterator LLCullResult::beginOcclusionGroups() { - return mOcclusionGroups; + return &mOcclusionGroups[0]; } LLCullResult::sg_iterator LLCullResult::endOcclusionGroups() @@ -4807,7 +4815,7 @@ LLCullResult::sg_iterator LLCullResult::endOcclusionGroups() LLCullResult::sg_iterator LLCullResult::beginDrawableGroups() { - return mDrawableGroups; + return &mDrawableGroups[0]; } LLCullResult::sg_iterator LLCullResult::endDrawableGroups() @@ -4817,7 +4825,7 @@ LLCullResult::sg_iterator LLCullResult::endDrawableGroups() LLCullResult::drawable_iterator LLCullResult::beginVisibleList() { - return mVisibleList; + return &mVisibleList[0]; } LLCullResult::drawable_iterator LLCullResult::endVisibleList() @@ -4827,7 +4835,7 @@ LLCullResult::drawable_iterator LLCullResult::endVisibleList() LLCullResult::bridge_iterator LLCullResult::beginVisibleBridge() { - return mVisibleBridge; + return &mVisibleBridge[0]; } LLCullResult::bridge_iterator LLCullResult::endVisibleBridge() @@ -4837,7 +4845,7 @@ LLCullResult::bridge_iterator LLCullResult::endVisibleBridge() LLCullResult::drawinfo_iterator LLCullResult::beginRenderMap(U32 type) { - return mRenderMap[type]; + return &mRenderMap[type][0]; } LLCullResult::drawinfo_iterator LLCullResult::endRenderMap(U32 type) @@ -4853,10 +4861,10 @@ void LLCullResult::pushVisibleGroup(LLSpatialGroup* group) } else { - pushBack((void**&) mVisibleGroups, mVisibleGroupsAllocated, (void*) group); + pushBack(mVisibleGroups, mVisibleGroupsAllocated, group); } ++mVisibleGroupsSize; - mVisibleGroupsEnd = mVisibleGroups+mVisibleGroupsSize; + mVisibleGroupsEnd = &mVisibleGroups[mVisibleGroupsSize]; } void LLCullResult::pushAlphaGroup(LLSpatialGroup* group) @@ -4867,10 +4875,10 @@ void LLCullResult::pushAlphaGroup(LLSpatialGroup* group) } else { - pushBack((void**&) mAlphaGroups, mAlphaGroupsAllocated, (void*) group); + pushBack(mAlphaGroups, mAlphaGroupsAllocated, group); } ++mAlphaGroupsSize; - mAlphaGroupsEnd = mAlphaGroups+mAlphaGroupsSize; + mAlphaGroupsEnd = &mAlphaGroups[mAlphaGroupsSize]; } void LLCullResult::pushOcclusionGroup(LLSpatialGroup* group) @@ -4881,10 +4889,10 @@ void LLCullResult::pushOcclusionGroup(LLSpatialGroup* group) } else { - pushBack((void**&) mOcclusionGroups, mOcclusionGroupsAllocated, (void*) group); + pushBack(mOcclusionGroups, mOcclusionGroupsAllocated, group); } ++mOcclusionGroupsSize; - mOcclusionGroupsEnd = mOcclusionGroups+mOcclusionGroupsSize; + mOcclusionGroupsEnd = &mOcclusionGroups[mOcclusionGroupsSize]; } void LLCullResult::pushDrawableGroup(LLSpatialGroup* group) @@ -4895,10 +4903,10 @@ void LLCullResult::pushDrawableGroup(LLSpatialGroup* group) } else { - pushBack((void**&) mDrawableGroups, mDrawableGroupsAllocated, (void*) group); + pushBack(mDrawableGroups, mDrawableGroupsAllocated, group); } ++mDrawableGroupsSize; - mDrawableGroupsEnd = mDrawableGroups+mDrawableGroupsSize; + mDrawableGroupsEnd = &mDrawableGroups[mDrawableGroupsSize]; } void LLCullResult::pushDrawable(LLDrawable* drawable) @@ -4909,10 +4917,10 @@ void LLCullResult::pushDrawable(LLDrawable* drawable) } else { - pushBack((void**&) mVisibleList, mVisibleListAllocated, (void*) drawable); + pushBack(mVisibleList, mVisibleListAllocated, drawable); } ++mVisibleListSize; - mVisibleListEnd = mVisibleList+mVisibleListSize; + mVisibleListEnd = &mVisibleList[mVisibleListSize]; } void LLCullResult::pushBridge(LLSpatialBridge* bridge) @@ -4923,10 +4931,10 @@ void LLCullResult::pushBridge(LLSpatialBridge* bridge) } else { - pushBack((void**&) mVisibleBridge, mVisibleBridgeAllocated, (void*) bridge); + pushBack(mVisibleBridge, mVisibleBridgeAllocated, bridge); } ++mVisibleBridgeSize; - mVisibleBridgeEnd = mVisibleBridge+mVisibleBridgeSize; + mVisibleBridgeEnd = &mVisibleBridge[mVisibleBridgeSize]; } void LLCullResult::pushDrawInfo(U32 type, LLDrawInfo* draw_info) @@ -4937,10 +4945,10 @@ void LLCullResult::pushDrawInfo(U32 type, LLDrawInfo* draw_info) } else { - pushBack((void**&) mRenderMap[type], mRenderMapAllocated[type], (void*) draw_info); + pushBack(mRenderMap[type], mRenderMapAllocated[type], draw_info); } ++mRenderMapSize[type]; - mRenderMapEnd[type] = mRenderMap[type] + mRenderMapSize[type]; + mRenderMapEnd[type] = &(mRenderMap[type][mRenderMapSize[type]]); } diff --git a/indra/newview/llspatialpartition.h b/indra/newview/llspatialpartition.h index e63037b4a8..b1706d9d35 100644 --- a/indra/newview/llspatialpartition.h +++ b/indra/newview/llspatialpartition.h @@ -569,10 +569,10 @@ class LLCullResult public: LLCullResult(); - typedef LLSpatialGroup** sg_list_t; - typedef LLDrawable** drawable_list_t; - typedef LLSpatialBridge** bridge_list_t; - typedef LLDrawInfo** drawinfo_list_t; + typedef std::vector<LLSpatialGroup*> sg_list_t; + typedef std::vector<LLDrawable*> drawable_list_t; + typedef std::vector<LLSpatialBridge*> bridge_list_t; + typedef std::vector<LLDrawInfo*> drawinfo_list_t; typedef LLSpatialGroup** sg_iterator; typedef LLSpatialBridge** bridge_iterator; @@ -622,7 +622,7 @@ public: private: - void pushBack(void** &head, U32& count, void* val); + template <class T, class V> void pushBack(T &head, U32& count, V* val); U32 mVisibleGroupsSize; U32 mAlphaGroupsSize; |