1 //===-- StringPool.cpp - Interned string pool -----------------------------===//
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
7 //===----------------------------------------------------------------------===//
9 // This file implements the StringPool class.
11 //===----------------------------------------------------------------------===//
13 #include "llvm/Support/StringPool.h"
14 #include "llvm/ADT/StringRef.h"
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
);