MCPcopy Create free account
hub / github.com/beefytech/Beef / ArrayImpl

Class ArrayImpl

BeefySysLib/util/Array.h:430–760  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

428// NON-POD
429template <typename T, typename TAlloc, bool TIsPod>
430class ArrayImpl : public ArrayBase<T, TAlloc>
431{
432public:
433 typedef int int_cosize;
434
435protected:
436 void MoveArray(T* to, T* from, intptr count)
437 {
438 if (to < from)
439 {
440 // Prefer in-order moves
441 for (intptr i = 0; i < count; i++)
442 new (&to[i]) T(std::move(from[i]));
443 }
444 else
445 {
446 for (intptr i = count - 1; i >= 0; i--)
447 new (&to[i]) T(std::move(from[i]));
448 }
449 }
450
451 void SetBufferSize(intptr newSize)
452 {
453 T* newVals = TAlloc::template allocate<T>(newSize);
454 if (this->mVals != NULL)
455 {
456 if (this->mSize > 0)
457 MoveArray(newVals, this->mVals, this->mSize);
458 TAlloc::deallocate(this->mVals);
459 }
460 this->mVals = newVals;
461 this->mAllocSize = (int_cosize)newSize;
462 }
463
464 void EnsureFree(intptr freeCount)
465 {
466 if (this->mSize + freeCount > this->mAllocSize)
467 SetBufferSize(BF_MAX(this->mAllocSize + this->mAllocSize / 2 + 1, this->mSize + freeCount));
468 }
469
470public:
471 using ArrayBase<T, TAlloc>::ArrayBase;
472
473 ArrayImpl() : ArrayBase<T, TAlloc>()
474 {
475
476 }
477
478 ArrayImpl(const ArrayImpl& val)
479 {
480 this->mVals = NULL;
481 this->mSize = 0;
482 this->mAllocSize = 0;
483
484 *this = val;
485 }
486
487 ArrayImpl(ArrayImpl&& val) : ArrayBase<T, TAlloc>(std::move(val))

Callers

nothing calls this directly

Calls 2

AddMethod · 0.95
ResizeFunction · 0.85

Tested by

no test coverage detected