Coverage Report

Created: 2019-07-24 05:18

/Users/buildslave/jenkins/workspace/clang-stage2-coverage-R/llvm/lib/Support/StringSaver.cpp
Line
Count
Source
1
//===-- StringSaver.cpp ---------------------------------------------------===//
2
//
3
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4
// See https://llvm.org/LICENSE.txt for license information.
5
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6
//
7
//===----------------------------------------------------------------------===//
8
9
#include "llvm/Support/StringSaver.h"
10
11
using namespace llvm;
12
13
2.84M
StringRef StringSaver::save(StringRef S) {
14
2.84M
  char *P = Alloc.Allocate<char>(S.size() + 1);
15
2.84M
  if (!S.empty())
16
2.84M
    memcpy(P, S.data(), S.size());
17
2.84M
  P[S.size()] = '\0';
18
2.84M
  return StringRef(P, S.size());
19
2.84M
}
20
21
36.9k
StringRef UniqueStringSaver::save(StringRef S) {
22
36.9k
  auto R = Unique.insert(S);
23
36.9k
  if (R.second)                 // cache miss, need to actually save the string
24
9.80k
    *R.first = Strings.save(S); // safe replacement with equal value
25
36.9k
  return *R.first;
26
36.9k
}