2
0

StringPool.cpp 978 B

1234567891011121314151617181920212223242526272829303132333435
  1. //===-- StringPool.cpp - Interned string pool -----------------------------===//
  2. //
  3. // The LLVM Compiler Infrastructure
  4. //
  5. // This file is distributed under the University of Illinois Open Source
  6. // License. See LICENSE.TXT for details.
  7. //
  8. //===----------------------------------------------------------------------===//
  9. //
  10. // This file implements the StringPool class.
  11. //
  12. //===----------------------------------------------------------------------===//
  13. #include "llvm/Support/StringPool.h"
  14. #include "llvm/ADT/StringRef.h"
  15. using namespace llvm;
  16. StringPool::StringPool() {}
  17. StringPool::~StringPool() {
  18. assert(InternTable.empty() && "PooledStringPtr leaked!");
  19. }
  20. PooledStringPtr StringPool::intern(StringRef Key) {
  21. table_t::iterator I = InternTable.find(Key);
  22. if (I != InternTable.end())
  23. return PooledStringPtr(&*I);
  24. entry_t *S = entry_t::Create(Key);
  25. S->getValue().Pool = this;
  26. InternTable.insert(S);
  27. return PooledStringPtr(S);
  28. }