Allow the caller to pass in the hash.
authorRafael Espindola <rafael.espindola@gmail.com>
Wed, 5 Oct 2016 18:46:21 +0000 (18:46 +0000)
committerRafael Espindola <rafael.espindola@gmail.com>
Wed, 5 Oct 2016 18:46:21 +0000 (18:46 +0000)
If the caller already has the hash we don't have to compute it. This
will be used in lld.

llvm-svn: 283359

llvm/include/llvm/MC/StringTableBuilder.h
llvm/lib/MC/StringTableBuilder.cpp

index 90d1bc3..e63a353 100644 (file)
@@ -31,6 +31,7 @@ public:
   }
 
   StringRef val() const { return StringRef(P, Size); }
+  uint32_t size() const { return Size; }
   uint32_t hash() const { return Hash; }
 };
 
@@ -56,7 +57,8 @@ public:
   /// \brief Add a string to the builder. Returns the position of S in the
   /// table. The position will be changed if finalize is used.
   /// Can only be used before the table is finalized.
-  size_t add(StringRef S);
+  size_t add(CachedHashString S);
+  size_t add(StringRef S) { return add(CachedHashString(S)); }
 
   /// \brief Analyze the strings and build the final table. No more strings can
   /// be added after this point.
@@ -68,7 +70,8 @@ public:
 
   /// \brief Get the offest of a string in the string table. Can only be used
   /// after the table is finalized.
-  size_t getOffset(StringRef S) const;
+  size_t getOffset(CachedHashString S) const;
+  size_t getOffset(StringRef S) const { return getOffset(CachedHashString(S)); }
 
   size_t getSize() const { return Size; }
   void clear();
index 63554fa..42292d4 100644 (file)
@@ -183,14 +183,14 @@ void StringTableBuilder::clear() {
   StringIndexMap.clear();
 }
 
-size_t StringTableBuilder::getOffset(StringRef S) const {
+size_t StringTableBuilder::getOffset(CachedHashString S) const {
   assert(isFinalized());
   auto I = StringIndexMap.find(S);
   assert(I != StringIndexMap.end() && "String is not in table!");
   return I->second;
 }
 
-size_t StringTableBuilder::add(StringRef S) {
+size_t StringTableBuilder::add(CachedHashString S) {
   if (K == WinCOFF)
     assert(S.size() > COFF::NameSize && "Short string in COFF string table!");