Fixed some bugs.
[llvm/zpu.git] / lib / Support / StringPool.cpp
blobff607cf8c4adddee0547868a6b03567febc77185
1 //===-- StringPool.cpp - Interned string pool -----------------------------===//
2 //
3 // The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 //
10 // This file implements the StringPool class.
12 //===----------------------------------------------------------------------===//
14 #include "llvm/Support/StringPool.h"
15 #include "llvm/ADT/StringRef.h"
17 using namespace llvm;
19 StringPool::StringPool() {}
21 StringPool::~StringPool() {
22 assert(InternTable.empty() && "PooledStringPtr leaked!");
25 PooledStringPtr StringPool::intern(StringRef Key) {
26 table_t::iterator I = InternTable.find(Key);
27 if (I != InternTable.end())
28 return PooledStringPtr(&*I);
30 entry_t *S = entry_t::Create(Key.begin(), Key.end());
31 S->getValue().Pool = this;
32 InternTable.insert(S);
34 return PooledStringPtr(S);