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