Recommit r373598 "[yaml2obj/obj2yaml] - Add support for SHT_LLVM_ADDRSIG sections."
[llvm-complete.git] / lib / Support / StringPool.cpp
blob82351017b8ccac59f71634600f823ab817f7ec29
1 //===-- StringPool.cpp - Interned string pool -----------------------------===//
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 // This file implements the StringPool class.
11 //===----------------------------------------------------------------------===//
13 #include "llvm/Support/StringPool.h"
14 #include "llvm/ADT/StringRef.h"
16 using namespace llvm;
18 StringPool::StringPool() {}
20 StringPool::~StringPool() {
21 assert(InternTable.empty() && "PooledStringPtr leaked!");
24 PooledStringPtr StringPool::intern(StringRef Key) {
25 table_t::iterator I = InternTable.find(Key);
26 if (I != InternTable.end())
27 return PooledStringPtr(&*I);
29 entry_t *S = entry_t::Create(Key);
30 S->getValue().Pool = this;
31 InternTable.insert(S);
33 return PooledStringPtr(S);