LLVM API Documentation

SmallVector.cpp
Go to the documentation of this file.
00001 //===- llvm/ADT/SmallVector.cpp - 'Normally small' vectors ----------------===//
00002 //
00003 //                     The LLVM Compiler Infrastructure
00004 //
00005 // This file is distributed under the University of Illinois Open Source
00006 // License. See LICENSE.TXT for details.
00007 //
00008 //===----------------------------------------------------------------------===//
00009 //
00010 // This file implements the SmallVector class.
00011 //
00012 //===----------------------------------------------------------------------===//
00013 
00014 #include "llvm/ADT/SmallVector.h"
00015 using namespace llvm;
00016 
00017 /// grow_pod - This is an implementation of the grow() method which only works
00018 /// on POD-like datatypes and is out of line to reduce code duplication.
00019 void SmallVectorBase::grow_pod(void *FirstEl, size_t MinSizeInBytes,
00020                                size_t TSize) {
00021   size_t CurSizeBytes = size_in_bytes();
00022   size_t NewCapacityInBytes = 2 * capacity_in_bytes() + TSize; // Always grow.
00023   if (NewCapacityInBytes < MinSizeInBytes)
00024     NewCapacityInBytes = MinSizeInBytes;
00025 
00026   void *NewElts;
00027   if (BeginX == FirstEl) {
00028     NewElts = malloc(NewCapacityInBytes);
00029 
00030     // Copy the elements over.  No need to run dtors on PODs.
00031     memcpy(NewElts, this->BeginX, CurSizeBytes);
00032   } else {
00033     // If this wasn't grown from the inline copy, grow the allocated space.
00034     NewElts = realloc(this->BeginX, NewCapacityInBytes);
00035   }
00036 
00037   this->EndX = (char*)NewElts+CurSizeBytes;
00038   this->BeginX = NewElts;
00039   this->CapacityX = (char*)this->BeginX + NewCapacityInBytes;
00040 }