LLVM API Documentation
00001 //===-- StringPool.cpp - Interned string pool -----------------------------===// 00002 // 00003 // The LLVM Compiler Infrastructure 00004 // 00005 // This file is distributed under the University of Illinois Open Source 00006 // License. See LICENSE.TXT for details. 00007 // 00008 //===----------------------------------------------------------------------===// 00009 // 00010 // This file implements the StringPool class. 00011 // 00012 //===----------------------------------------------------------------------===// 00013 00014 #include "llvm/Support/StringPool.h" 00015 #include "llvm/Support/Streams.h" 00016 #include "llvm/ADT/StringRef.h" 00017 00018 using namespace llvm; 00019 00020 StringPool::StringPool() {} 00021 00022 StringPool::~StringPool() { 00023 assert(InternTable.empty() && "PooledStringPtr leaked!"); 00024 } 00025 00026 PooledStringPtr StringPool::intern(const StringRef &Key) { 00027 table_t::iterator I = InternTable.find(Key); 00028 if (I != InternTable.end()) 00029 return PooledStringPtr(&*I); 00030 00031 entry_t *S = entry_t::Create(Key.begin(), Key.end()); 00032 S->getValue().Pool = this; 00033 InternTable.insert(S); 00034 00035 return PooledStringPtr(S); 00036 }