Coverage Report

Created: 2017-10-03 07:32

/Users/buildslave/jenkins/sharedspace/clang-stage2-coverage-R@2/llvm/lib/Support/SmallVector.cpp
Line
Count
Source (jump to first uncovered line)
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
14
#include "llvm/ADT/SmallVector.h"
15
using namespace llvm;
16
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,
20
161M
                               size_t TSize) {
21
161M
  size_t CurSizeBytes = size_in_bytes();
22
161M
  size_t NewCapacityInBytes = 2 * capacity_in_bytes() + TSize; // Always grow.
23
161M
  if (NewCapacityInBytes < MinSizeInBytes)
24
12.9M
    NewCapacityInBytes = MinSizeInBytes;
25
161M
26
161M
  void *NewElts;
27
161M
  if (
BeginX == FirstEl161M
) {
28
103M
    NewElts = malloc(NewCapacityInBytes);
29
103M
    if (NewElts == nullptr)
30
0
      report_bad_alloc_error("Allocation of SmallVector element failed.");
31
103M
32
103M
    // Copy the elements over.  No need to run dtors on PODs.
33
103M
    memcpy(NewElts, this->BeginX, CurSizeBytes);
34
161M
  } else {
35
58.0M
    // If this wasn't grown from the inline copy, grow the allocated space.
36
58.0M
    NewElts = realloc(this->BeginX, NewCapacityInBytes);
37
58.0M
    if (NewElts == nullptr)
38
0
      report_bad_alloc_error("Reallocation of SmallVector element failed.");
39
58.0M
  }
40
161M
41
161M
  this->EndX = (char*)NewElts+CurSizeBytes;
42
161M
  this->BeginX = NewElts;
43
161M
  this->CapacityX = (char*)this->BeginX + NewCapacityInBytes;
44
161M
}