1 //===- NonRelocatableStringpool.cpp - A simple stringpool ----------------===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 #include "NonRelocatableStringpool.h"
15 DwarfStringPoolEntryRef NonRelocatableStringpool::getEntry(StringRef S) {
16 if (S.empty() && !Strings.empty())
19 auto I = Strings.insert({S, DwarfStringPoolEntry()});
20 auto &Entry = I.first->second;
21 if (I.second || Entry.Index == -1U) {
22 Entry.Index = NumEntries++;
23 Entry.Offset = CurrentEndOffset;
24 Entry.Symbol = nullptr;
25 CurrentEndOffset += S.size() + 1;
27 return DwarfStringPoolEntryRef(*I.first);
30 StringRef NonRelocatableStringpool::internString(StringRef S) {
31 DwarfStringPoolEntry Entry{nullptr, 0, -1U};
32 auto InsertResult = Strings.insert({S, Entry});
33 return InsertResult.first->getKey();
36 std::vector<DwarfStringPoolEntryRef>
37 NonRelocatableStringpool::getEntries() const {
38 std::vector<DwarfStringPoolEntryRef> Result;
39 Result.reserve(Strings.size());
40 for (const auto &E : Strings)
41 Result.emplace_back(E);
43 Result.begin(), Result.end(),
44 [](const DwarfStringPoolEntryRef A, const DwarfStringPoolEntryRef B) {
45 return A.getIndex() < B.getIndex();
50 } // namespace dsymutil