MCPcopy Create free account
hub / github.com/NVIDIAGameWorks/PhysX / replaceWithLast

Method replaceWithLast

physx/source/common/src/CmPtrTable.cpp:154–192  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

152}
153
154void PtrTable::replaceWithLast(PxU32 index, PtrTableStorageManager& sm)
155{
156 PX_ASSERT(mCount!=0);
157
158 if(mCount == 1) // 1 -> 0 easy case
159 {
160 PX_ASSERT(mOwnsMemory);
161 PX_ASSERT(mBufferUsed);
162
163 mList = NULL;
164 mCount = 0;
165 mBufferUsed = false;
166 }
167 else if(mCount == 2) // 2 -> 1 easy case
168 {
169 PX_ASSERT(!mBufferUsed);
170 void* ptr = mList[1-index];
171 if(mOwnsMemory)
172 sm.deallocate(mList, 2*sizeof(void*));
173 mSingle = ptr;
174 mCount = 1;
175 mBufferUsed = true;
176 mOwnsMemory = true;
177 }
178 else
179 {
180 PX_ASSERT(!mBufferUsed);
181
182 mList[index] = mList[--mCount]; // remove before adjusting memory
183
184 if(!mOwnsMemory) // don't own the memory, must alloc
185 realloc(0, Ps::nextPowerOfTwo(PxU32(mCount)-1), sm); // if currently a power of 2, don't jump to the next one
186
187 else if(Ps::isPowerOfTwo(mCount)) // own the memory, and implicit capacity requires that we downsize
188 realloc(PxU32(mCount)*2, PxU32(mCount), sm); // ... from the next power of 2, which was the old implicit capacity
189
190 PX_ASSERT(mOwnsMemory);
191 }
192}
193
194void Cm::PtrTable::getBinaryMetaData(PxOutputStream& stream)
195{

Calls 3

nextPowerOfTwoFunction · 0.85
isPowerOfTwoFunction · 0.85
deallocateMethod · 0.45

Tested by

no test coverage detected