LLVM  10.0.0svn
StringSaver.cpp
Go to the documentation of this file.
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 
10 
11 using namespace llvm;
12 
14  char *P = Alloc.Allocate<char>(S.size() + 1);
15  if (!S.empty())
16  memcpy(P, S.data(), S.size());
17  P[S.size()] = '\0';
18  return StringRef(P, S.size());
19 }
20 
22  auto R = Unique.insert(S);
23  if (R.second) // cache miss, need to actually save the string
24  *R.first = Strings.save(S); // safe replacement with equal value
25  return *R.first;
26 }
This class represents lattice values for constants.
Definition: AllocatorList.h:23
LLVM_NODISCARD bool empty() const
empty - Check if the string is empty.
Definition: StringRef.h:140
LLVM_NODISCARD size_t size() const
size - Get the string size.
Definition: StringRef.h:144
StringRef save(const char *S)
Definition: StringSaver.h:50
#define P(N)
StringRef save(const char *S)
Definition: StringSaver.h:28
LLVM_ATTRIBUTE_RETURNS_NONNULL LLVM_ATTRIBUTE_RETURNS_NOALIAS void * Allocate(size_t Size, Align Alignment)
Allocate space at the specified alignment.
Definition: Allocator.h:215
LLVM_NODISCARD const char * data() const
data - Get a pointer to the start of the string (which may not be null terminated).
Definition: StringRef.h:136
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:48