blob: b9c1fd0465bd69d1171955cadcb71fddcfc56c20 [file] [log] [blame]
Gordon Henriksen985cb622007-12-08 17:07:47 +00001//===-- StringPool.cpp - Interned string pool -----------------------------===//
2//
3// The LLVM Compiler Infrastructure
4//
Chris Lattner4ee451d2007-12-29 20:36:04 +00005// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
Gordon Henriksen985cb622007-12-08 17:07:47 +00007//
8//===----------------------------------------------------------------------===//
9//
10// This file implements the StringPool class.
11//
12//===----------------------------------------------------------------------===//
13
14#include "llvm/Support/StringPool.h"
15#include "llvm/Support/Streams.h"
16
17using namespace llvm;
18
19StringPool::StringPool() {}
20
21StringPool::~StringPool() {
22 assert(InternTable.empty() && "PooledStringPtr leaked!");
23}
24
25PooledStringPtr StringPool::intern(const char *Begin, const char *End) {
26 table_t::iterator I = InternTable.find(Begin, End);
27 if (I != InternTable.end())
28 return PooledStringPtr(&*I);
29
30 entry_t *S = entry_t::Create(Begin, End);
31 S->getValue().Pool = this;
32 InternTable.insert(S);
33
34 return PooledStringPtr(S);
35}