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 16using namespace llvm; 17 18StringPool::StringPool() {} 19 20StringPool::~StringPool() { 21 assert(InternTable.empty() && "PooledStringPtr leaked!"); 22} 23 24PooledStringPtr 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} 35