2
0

SmallVector.cpp 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. //===- llvm/ADT/SmallVector.cpp - 'Normally small' vectors ----------------===//
  2. //
  3. // The LLVM Compiler Infrastructure
  4. //
  5. // This file is distributed under the University of Illinois Open Source
  6. // License. See LICENSE.TXT for details.
  7. //
  8. //===----------------------------------------------------------------------===//
  9. //
  10. // This file implements the SmallVector class.
  11. //
  12. //===----------------------------------------------------------------------===//
  13. #include "llvm/ADT/SmallVector.h"
  14. using namespace llvm;
  15. /// grow_pod - This is an implementation of the grow() method which only works
  16. /// on POD-like datatypes and is out of line to reduce code duplication.
  17. void SmallVectorBase::grow_pod(void *FirstEl, size_t MinSizeInBytes,
  18. size_t TSize) {
  19. size_t CurSizeBytes = size_in_bytes();
  20. size_t NewCapacityInBytes = 2 * capacity_in_bytes() + TSize; // Always grow.
  21. if (NewCapacityInBytes < MinSizeInBytes)
  22. NewCapacityInBytes = MinSizeInBytes;
  23. void *NewElts;
  24. if (BeginX == FirstEl) {
  25. NewElts = new char[NewCapacityInBytes]; // HLSL Change: Use overridable operator new
  26. // Copy the elements over. No need to run dtors on PODs.
  27. memcpy(NewElts, this->BeginX, CurSizeBytes);
  28. } else {
  29. // If this wasn't grown from the inline copy, grow the allocated space.
  30. // HLSL Change Begins: Use overridable operator new
  31. NewElts = new char[NewCapacityInBytes];
  32. memcpy(NewElts, this->BeginX, CurSizeBytes);
  33. delete[] (char*)this->BeginX;
  34. // HLSL Change Ends
  35. }
  36. assert(NewElts && "Out of memory");
  37. this->EndX = (char*)NewElts+CurSizeBytes;
  38. this->BeginX = NewElts;
  39. this->CapacityX = (char*)this->BeginX + NewCapacityInBytes;
  40. }