]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - contrib/llvm-project/llvm/lib/Support/StringPool.cpp
MFV r357163:
[FreeBSD/FreeBSD.git] / contrib / llvm-project / llvm / lib / Support / StringPool.cpp
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.
10 //
11 //===----------------------------------------------------------------------===//
12
13 #include "llvm/Support/StringPool.h"
14 #include "llvm/ADT/StringRef.h"
15
16 using namespace llvm;
17
18 StringPool::StringPool() {}
19
20 StringPool::~StringPool() {
21   assert(InternTable.empty() && "PooledStringPtr leaked!");
22 }
23
24 PooledStringPtr StringPool::intern(StringRef Key) {
25   table_t::iterator I = InternTable.find(Key);
26   if (I != InternTable.end())
27     return PooledStringPtr(&*I);
28
29   entry_t *S = entry_t::Create(Key);
30   S->getValue().Pool = this;
31   InternTable.insert(S);
32
33   return PooledStringPtr(S);
34 }