1f4a2713aSLionel Sambuc //===-- StringPool.cpp - Interned string pool -----------------------------===// 2f4a2713aSLionel Sambuc // 3f4a2713aSLionel Sambuc // The LLVM Compiler Infrastructure 4f4a2713aSLionel Sambuc // 5f4a2713aSLionel Sambuc // This file is distributed under the University of Illinois Open Source 6f4a2713aSLionel Sambuc // License. See LICENSE.TXT for details. 7f4a2713aSLionel Sambuc // 8f4a2713aSLionel Sambuc //===----------------------------------------------------------------------===// 9f4a2713aSLionel Sambuc // 10f4a2713aSLionel Sambuc // This file implements the StringPool class. 11f4a2713aSLionel Sambuc // 12f4a2713aSLionel Sambuc //===----------------------------------------------------------------------===// 13f4a2713aSLionel Sambuc 14f4a2713aSLionel Sambuc #include "llvm/Support/StringPool.h" 15f4a2713aSLionel Sambuc #include "llvm/ADT/StringRef.h" 16f4a2713aSLionel Sambuc 17f4a2713aSLionel Sambuc using namespace llvm; 18f4a2713aSLionel Sambuc StringPool()19f4a2713aSLionel SambucStringPool::StringPool() {} 20f4a2713aSLionel Sambuc ~StringPool()21f4a2713aSLionel SambucStringPool::~StringPool() { 22f4a2713aSLionel Sambuc assert(InternTable.empty() && "PooledStringPtr leaked!"); 23f4a2713aSLionel Sambuc } 24f4a2713aSLionel Sambuc intern(StringRef Key)25f4a2713aSLionel SambucPooledStringPtr StringPool::intern(StringRef Key) { 26f4a2713aSLionel Sambuc table_t::iterator I = InternTable.find(Key); 27f4a2713aSLionel Sambuc if (I != InternTable.end()) 28f4a2713aSLionel Sambuc return PooledStringPtr(&*I); 29f4a2713aSLionel Sambuc 30*0a6a1f1dSLionel Sambuc entry_t *S = entry_t::Create(Key); 31f4a2713aSLionel Sambuc S->getValue().Pool = this; 32f4a2713aSLionel Sambuc InternTable.insert(S); 33f4a2713aSLionel Sambuc 34f4a2713aSLionel Sambuc return PooledStringPtr(S); 35f4a2713aSLionel Sambuc } 36