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