LLVM 20.0.0git
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
12
13using namespace llvm;
14
16 char *P = Alloc.Allocate<char>(S.size() + 1);
17 if (!S.empty())
18 memcpy(P, S.data(), S.size());
19 P[S.size()] = '\0';
20 return StringRef(P, S.size());
21}
22
24 SmallString<128> Storage;
25 return save(S.toStringRef(Storage));
26}
27
29 auto R = Unique.insert(S);
30 if (R.second) // cache miss, need to actually save the string
31 *R.first = Strings.save(S); // safe replacement with equal value
32 return *R.first;
33}
34
36 SmallString<128> Storage;
37 return save(S.toStringRef(Storage));
38}
#define P(N)
This file defines the SmallString class.
LLVM_ATTRIBUTE_RETURNS_NONNULL void * Allocate(size_t Size, Align Alignment)
Allocate space at the specified alignment.
Definition: Allocator.h:148
SmallString - A SmallString is just a SmallVector with methods and accessors that make it work better...
Definition: SmallString.h:26
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:50
constexpr bool empty() const
empty - Check if the string is empty.
Definition: StringRef.h:134
constexpr size_t size() const
size - Get the string size.
Definition: StringRef.h:137
constexpr const char * data() const
data - Get a pointer to the start of the string (which may not be null terminated).
Definition: StringRef.h:131
StringRef save(const char *S)
Definition: StringSaver.h:30
Twine - A lightweight data structure for efficiently representing the concatenation of temporary valu...
Definition: Twine.h:81
StringRef toStringRef(SmallVectorImpl< char > &Out) const
This returns the twine as a single StringRef if it can be represented as such.
Definition: Twine.h:492
StringRef save(const char *S)
Definition: StringSaver.h:52
std::pair< iterator, bool > insert(const ValueT &V)
Definition: DenseSet.h:206
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:18