2007-12-09 01:07:47 +08:00
|
|
|
//===-- StringPool.cpp - Interned string pool -----------------------------===//
|
|
|
|
//
|
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
2007-12-30 04:36:04 +08:00
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
2007-12-09 01:07:47 +08:00
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
//
|
|
|
|
// This file implements the StringPool class.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
#include "llvm/Support/StringPool.h"
|
2009-07-24 02:17:34 +08:00
|
|
|
#include "llvm/ADT/StringRef.h"
|
2007-12-09 01:07:47 +08:00
|
|
|
|
|
|
|
using namespace llvm;
|
|
|
|
|
|
|
|
StringPool::StringPool() {}
|
|
|
|
|
|
|
|
StringPool::~StringPool() {
|
|
|
|
assert(InternTable.empty() && "PooledStringPtr leaked!");
|
|
|
|
}
|
|
|
|
|
2010-07-15 06:38:02 +08:00
|
|
|
PooledStringPtr StringPool::intern(StringRef Key) {
|
2009-07-24 02:17:34 +08:00
|
|
|
table_t::iterator I = InternTable.find(Key);
|
2007-12-09 01:07:47 +08:00
|
|
|
if (I != InternTable.end())
|
|
|
|
return PooledStringPtr(&*I);
|
2018-07-31 03:41:25 +08:00
|
|
|
|
2014-06-11 13:35:56 +08:00
|
|
|
entry_t *S = entry_t::Create(Key);
|
2007-12-09 01:07:47 +08:00
|
|
|
S->getValue().Pool = this;
|
|
|
|
InternTable.insert(S);
|
2018-07-31 03:41:25 +08:00
|
|
|
|
2007-12-09 01:07:47 +08:00
|
|
|
return PooledStringPtr(S);
|
|
|
|
}
|