2007-12-08 17:07:47 +00:00
|
|
|
//===-- StringPool.cpp - Interned string pool -----------------------------===//
|
|
|
|
//
|
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
2007-12-29 20:36:04 +00:00
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
2007-12-08 17:07:47 +00:00
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
//
|
|
|
|
// This file implements the StringPool class.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
#include "llvm/Support/StringPool.h"
|
|
|
|
#include "llvm/Support/Streams.h"
|
2009-07-23 18:17:34 +00:00
|
|
|
#include "llvm/ADT/StringRef.h"
|
2007-12-08 17:07:47 +00:00
|
|
|
|
|
|
|
using namespace llvm;
|
|
|
|
|
|
|
|
StringPool::StringPool() {}
|
|
|
|
|
|
|
|
StringPool::~StringPool() {
|
|
|
|
assert(InternTable.empty() && "PooledStringPtr leaked!");
|
|
|
|
}
|
|
|
|
|
2009-07-23 18:17:34 +00:00
|
|
|
PooledStringPtr StringPool::intern(const StringRef &Key) {
|
|
|
|
table_t::iterator I = InternTable.find(Key);
|
2007-12-08 17:07:47 +00:00
|
|
|
if (I != InternTable.end())
|
|
|
|
return PooledStringPtr(&*I);
|
|
|
|
|
2009-07-23 18:17:34 +00:00
|
|
|
entry_t *S = entry_t::Create(Key.begin(), Key.end());
|
2007-12-08 17:07:47 +00:00
|
|
|
S->getValue().Pool = this;
|
|
|
|
InternTable.insert(S);
|
|
|
|
|
|
|
|
return PooledStringPtr(S);
|
|
|
|
}
|