Gordon Henriksen | 985cb62 | 2007-12-08 17:07:47 +0000 | [diff] [blame] | 1 | //===-- StringPool.cpp - Interned string pool -----------------------------===// |
| 2 | // |
| 3 | // The LLVM Compiler Infrastructure |
| 4 | // |
Chris Lattner | 4ee451d | 2007-12-29 20:36:04 +0000 | [diff] [blame] | 5 | // This file is distributed under the University of Illinois Open Source |
| 6 | // License. See LICENSE.TXT for details. |
Gordon Henriksen | 985cb62 | 2007-12-08 17:07:47 +0000 | [diff] [blame] | 7 | // |
| 8 | //===----------------------------------------------------------------------===// |
| 9 | // |
| 10 | // This file implements the StringPool class. |
| 11 | // |
| 12 | //===----------------------------------------------------------------------===// |
| 13 | |
| 14 | #include "llvm/Support/StringPool.h" |
Daniel Dunbar | 6316fbc | 2009-07-23 18:17:34 +0000 | [diff] [blame] | 15 | #include "llvm/ADT/StringRef.h" |
Gordon Henriksen | 985cb62 | 2007-12-08 17:07:47 +0000 | [diff] [blame] | 16 | |
| 17 | using namespace llvm; |
| 18 | |
| 19 | StringPool::StringPool() {} |
| 20 | |
| 21 | StringPool::~StringPool() { |
| 22 | assert(InternTable.empty() && "PooledStringPtr leaked!"); |
| 23 | } |
| 24 | |
Benjamin Kramer | 38e5989 | 2010-07-14 22:38:02 +0000 | [diff] [blame] | 25 | PooledStringPtr StringPool::intern(StringRef Key) { |
Daniel Dunbar | 6316fbc | 2009-07-23 18:17:34 +0000 | [diff] [blame] | 26 | table_t::iterator I = InternTable.find(Key); |
Gordon Henriksen | 985cb62 | 2007-12-08 17:07:47 +0000 | [diff] [blame] | 27 | if (I != InternTable.end()) |
| 28 | return PooledStringPtr(&*I); |
| 29 | |
Daniel Dunbar | 6316fbc | 2009-07-23 18:17:34 +0000 | [diff] [blame] | 30 | entry_t *S = entry_t::Create(Key.begin(), Key.end()); |
Gordon Henriksen | 985cb62 | 2007-12-08 17:07:47 +0000 | [diff] [blame] | 31 | S->getValue().Pool = this; |
| 32 | InternTable.insert(S); |
| 33 | |
| 34 | return PooledStringPtr(S); |
| 35 | } |