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