LLVM API Documentation

StringPool.cpp
Go to the documentation of this file.
00001 //===-- StringPool.cpp - Interned string pool -----------------------------===//
00002 //
00003 //                     The LLVM Compiler Infrastructure
00004 //
00005 // This file is distributed under the University of Illinois Open Source
00006 // License. See LICENSE.TXT for details.
00007 //
00008 //===----------------------------------------------------------------------===//
00009 //
00010 // This file implements the StringPool class.
00011 //
00012 //===----------------------------------------------------------------------===//
00013 
00014 #include "llvm/Support/StringPool.h"
00015 #include "llvm/ADT/StringRef.h"
00016 
00017 using namespace llvm;
00018 
00019 StringPool::StringPool() {}
00020 
00021 StringPool::~StringPool() {
00022   assert(InternTable.empty() && "PooledStringPtr leaked!");
00023 }
00024 
00025 PooledStringPtr StringPool::intern(StringRef Key) {
00026   table_t::iterator I = InternTable.find(Key);
00027   if (I != InternTable.end())
00028     return PooledStringPtr(&*I);
00029   
00030   entry_t *S = entry_t::Create(Key);
00031   S->getValue().Pool = this;
00032   InternTable.insert(S);
00033   
00034   return PooledStringPtr(S);
00035 }