[llvm] 953a814 - Remove the llvm/Support/StringPool.h file and related support now that it has no clients. A plain old StringSet<> is a better replacement.

Chris Lattner via llvm-commits llvm-commits at lists.llvm.org
Thu Apr 16 17:57:53 PDT 2020


Author: Chris Lattner
Date: 2020-04-16T17:57:39-07:00
New Revision: 953a814aae4997e50e73e8d3e6eb699d6b732bbc

URL: https://github.com/llvm/llvm-project/commit/953a814aae4997e50e73e8d3e6eb699d6b732bbc
DIFF: https://github.com/llvm/llvm-project/commit/953a814aae4997e50e73e8d3e6eb699d6b732bbc.diff

LOG: Remove the llvm/Support/StringPool.h file and related support now that it has no clients.  A plain old StringSet<> is a better replacement.

Subscribers: mgorny, hiraditya, llvm-commits

Tags: #llvm

Differential Revision: https://reviews.llvm.org/D78336

Added: 
    

Modified: 
    llvm/lib/Support/CMakeLists.txt
    llvm/unittests/Support/CMakeLists.txt

Removed: 
    llvm/include/llvm/Support/StringPool.h
    llvm/lib/Support/StringPool.cpp
    llvm/unittests/Support/StringPool.cpp


################################################################################
diff  --git a/llvm/include/llvm/Support/StringPool.h b/llvm/include/llvm/Support/StringPool.h
deleted file mode 100644
index aecfbee915c7..000000000000
--- a/llvm/include/llvm/Support/StringPool.h
+++ /dev/null
@@ -1,142 +0,0 @@
-//===- StringPool.h - Intern'd string pool ----------------------*- C++ -*-===//
-//
-// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
-// See https://llvm.org/LICENSE.txt for license information.
-// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
-//
-//===----------------------------------------------------------------------===//
-//
-// This file declares an interned string pool with separately malloc and
-// reference counted entries.  This can reduce the cost of strings by using the
-// same storage for identical strings.
-//
-// To intern a string:
-//
-//   StringPool Pool;
-//   PooledStringPtr Str = Pool.intern("wakka wakka");
-//
-// To use the value of an interned string, use operator bool and operator*:
-//
-//   if (Str)
-//     cerr << "the string is" << *Str << "\n";
-//
-// Pooled strings are immutable, but you can change a PooledStringPtr to point
-// to another instance. So that interned strings can eventually be freed,
-// strings in the string pool are reference-counted (automatically).
-//
-//===----------------------------------------------------------------------===//
-
-#ifndef LLVM_SUPPORT_STRINGPOOL_H
-#define LLVM_SUPPORT_STRINGPOOL_H
-
-#include "llvm/ADT/StringMap.h"
-
-namespace llvm {
-
-class PooledStringPtr;
-
-/// StringPool - An interned string pool. Use the intern method to add a
-/// string. Strings are removed automatically as PooledStringPtrs are
-/// destroyed.
-class StringPool {
-  /// PooledString - This is the value of an entry in the pool's interning
-  /// table.
-  struct PooledString {
-    StringPool *pool = nullptr; ///< So the string can remove itself.
-    unsigned refcount = 0;      ///< Number of referencing PooledStringPtrs.
-
-  public:
-    PooledString() = default;
-  };
-
-  friend class PooledStringPtr;
-  using Entry = StringMapEntry<PooledString>;
-  StringMap<PooledString> internTable;
-
-public:
-  StringPool();
-  ~StringPool();
-
-  /// intern - Adds a string to the pool and returns a reference-counted
-  /// pointer to it. No additional memory is allocated if the string already
-  /// exists in the pool.
-  PooledStringPtr intern(StringRef string);
-
-  /// empty - Checks whether the pool is empty. Returns true if so.
-  bool empty() const { return internTable.empty(); }
-};
-
-/// PooledStringPtr - A pointer to an interned string. Use operator bool to
-/// test whether the pointer is valid, and operator * to get the string if so.
-/// This is a lightweight value class with storage requirements equivalent to
-/// a single pointer, but it does have reference-counting overhead when
-/// copied.
-class PooledStringPtr {
-  using Entry = StringPool::Entry;
-  Entry *entry = nullptr;
-
-public:
-  PooledStringPtr() = default;
-
-  explicit PooledStringPtr(Entry *e) : entry(e) {
-    if (entry)
-      ++entry->getValue().refcount;
-  }
-
-  PooledStringPtr(const PooledStringPtr &that) : entry(that.entry) {
-    if (entry)
-      ++entry->getValue().refcount;
-  }
-
-  PooledStringPtr &operator=(const PooledStringPtr &that) {
-    if (entry != that.entry) {
-      clear();
-      entry = that.entry;
-      if (entry)
-        ++entry->getValue().refcount;
-    }
-    return *this;
-  }
-
-  void clear() {
-    if (!entry)
-      return;
-    if (--entry->getValue().refcount == 0) {
-      entry->getValue().pool->internTable.remove(entry);
-      MallocAllocator allocator;
-      entry->Destroy(allocator);
-    }
-    entry = nullptr;
-  }
-
-  ~PooledStringPtr() { clear(); }
-
-  const char *begin() const {
-    assert(*this && "Attempt to dereference empty PooledStringPtr!");
-    return entry->getKeyData();
-  }
-
-  const char *end() const {
-    assert(*this && "Attempt to dereference empty PooledStringPtr!");
-    return entry->getKeyData() + entry->getKeyLength();
-  }
-
-  unsigned size() const {
-    assert(*this && "Attempt to dereference empty PooledStringPtr!");
-    return entry->getKeyLength();
-  }
-
-  const char *operator*() const { return begin(); }
-  explicit operator bool() const { return entry != nullptr; }
-
-  bool operator==(const PooledStringPtr &that) const {
-    return entry == that.entry;
-  }
-  bool operator!=(const PooledStringPtr &that) const {
-    return entry != that.entry;
-  }
-};
-
-} // end namespace llvm
-
-#endif // LLVM_SUPPORT_STRINGPOOL_H

diff  --git a/llvm/lib/Support/CMakeLists.txt b/llvm/lib/Support/CMakeLists.txt
index b2071bee4d2d..185aff780bd8 100644
--- a/llvm/lib/Support/CMakeLists.txt
+++ b/llvm/lib/Support/CMakeLists.txt
@@ -138,7 +138,6 @@ add_llvm_component_library(LLVMSupport
   Statistic.cpp
   StringExtras.cpp
   StringMap.cpp
-  StringPool.cpp
   StringSaver.cpp
   StringRef.cpp
   SymbolRemappingReader.cpp

diff  --git a/llvm/lib/Support/StringPool.cpp b/llvm/lib/Support/StringPool.cpp
deleted file mode 100644
index 7d345df14cad..000000000000
--- a/llvm/lib/Support/StringPool.cpp
+++ /dev/null
@@ -1,33 +0,0 @@
-//===-- StringPool.cpp - Intern'd string pool -----------------------------===//
-//
-// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
-// See https://llvm.org/LICENSE.txt for license information.
-// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
-//
-//===----------------------------------------------------------------------===//
-//
-// This file implements the StringPool class.
-//
-//===----------------------------------------------------------------------===//
-
-#include "llvm/Support/StringPool.h"
-using namespace llvm;
-
-StringPool::StringPool() {}
-
-StringPool::~StringPool() {
-  assert(internTable.empty() && "PooledStringPtr leaked!");
-}
-
-PooledStringPtr StringPool::intern(StringRef key) {
-  auto it = internTable.find(key);
-  if (it != internTable.end())
-    return PooledStringPtr(&*it);
-
-  MallocAllocator allocator;
-  auto *entry = Entry::Create(key, allocator);
-  entry->getValue().pool = this;
-  internTable.insert(entry);
-
-  return PooledStringPtr(entry);
-}

diff  --git a/llvm/unittests/Support/CMakeLists.txt b/llvm/unittests/Support/CMakeLists.txt
index b9eeba165c96..75ca0e74f193 100644
--- a/llvm/unittests/Support/CMakeLists.txt
+++ b/llvm/unittests/Support/CMakeLists.txt
@@ -66,7 +66,6 @@ add_llvm_unittest(SupportTests
   ScaledNumberTest.cpp
   SourceMgrTest.cpp
   SpecialCaseListTest.cpp
-  StringPool.cpp
   SwapByteOrderTest.cpp
   SymbolRemappingReaderTest.cpp
   TarWriterTest.cpp

diff  --git a/llvm/unittests/Support/StringPool.cpp b/llvm/unittests/Support/StringPool.cpp
deleted file mode 100644
index 0a540e95acfd..000000000000
--- a/llvm/unittests/Support/StringPool.cpp
+++ /dev/null
@@ -1,30 +0,0 @@
-//===- llvm/unittest/Support/StringPoiil.cpp - StringPool tests -----------===//
-//
-// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
-// See https://llvm.org/LICENSE.txt for license information.
-// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
-//
-//===----------------------------------------------------------------------===//
-
-#include "llvm/Support/StringPool.h"
-#include "gtest/gtest.h"
-
-using namespace llvm;
-
-namespace {
-
-TEST(PooledStringPtrTest, OperatorEquals) {
-  StringPool pool;
-  const PooledStringPtr a = pool.intern("a");
-  const PooledStringPtr b = pool.intern("b");
-  EXPECT_FALSE(a == b);
-}
-
-TEST(PooledStringPtrTest, OperatorNotEquals) {
-  StringPool pool;
-  const PooledStringPtr a = pool.intern("a");
-  const PooledStringPtr b = pool.intern("b");
-  EXPECT_TRUE(a != b);
-}
-
-}


        


More information about the llvm-commits mailing list