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"
|
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!");
|
|
|
|
}
|
|
|
|
|
2010-07-14 22:38:02 +00:00
|
|
|
PooledStringPtr StringPool::intern(StringRef Key) {
|
2009-07-23 18:17:34 +00:00
|
|
|
table_t::iterator I = InternTable.find(Key);
|
2007-12-08 17:07:47 +00:00
|
|
|
if (I != InternTable.end())
|
|
|
|
return PooledStringPtr(&*I);
|
|
|
|
|
2014-06-11 05:35:56 +00:00
|
|
|
entry_t *S = entry_t::Create(Key);
|
2007-12-08 17:07:47 +00:00
|
|
|
S->getValue().Pool = this;
|
|
|
|
InternTable.insert(S);
|
|
|
|
|
|
|
|
return PooledStringPtr(S);
|
|
|
|
}
|