avoid creating a temporary string when reading the symbol table for a
authorChris Lattner <sabre@nondot.org>
Mon, 12 Feb 2007 18:53:43 +0000 (18:53 +0000)
committerChris Lattner <sabre@nondot.org>
Mon, 12 Feb 2007 18:53:43 +0000 (18:53 +0000)
module.  This speeds up the bcreader 11%.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@34198 91177308-0d34-0410-b5e6-96231b3b80d8

include/llvm/Bytecode/BytecodeHandler.h
lib/Bytecode/Reader/Analyzer.cpp
lib/Bytecode/Reader/Reader.cpp
lib/Bytecode/Reader/Reader.h

index b8aecb573417f97694a013d1ddec7ee47b6fc1f5..4084efa14cccf590eba8308179ed8afb4b5ec747 100644 (file)
@@ -175,7 +175,7 @@ public:
   virtual void handleSymbolTableValue(
     unsigned i,              ///< The index of the value in this plane
     unsigned slot,           ///< Slot number of the named value
-    const std::string& name  ///< Name of the value.
+    const char *name, unsigned NameLen  ///< Name of the value.
   ) {}
 
   /// @brief Handle the end of a value symbol table
index fe503f4d124d2cbf870f39562c5af42717dfaca5..880605c40fcbca989a8bff5e5170b6718e43f8ae 100644 (file)
@@ -250,10 +250,10 @@ public:
   }
 
   virtual void handleSymbolTableValue(unsigned TySlot, unsigned ValSlot, 
-                                      const std::string& name) {
+                                      const char *Name, unsigned NameLen) {
     if (os)
       *os << "        Value " << TySlot << " Slot=" << ValSlot
-         << " Name: " << name << "\n";
+          << " Name: " << std::string(Name, Name+NameLen) << "\n";
     if (ValSlot > bca.maxValueSlot)
       bca.maxValueSlot = ValSlot;
   }
index 0f0cf5e6cdfd70cf05405b86e14fcfc54940cf46..376c0702a3e77b36a7c9a29ccf1c7e7928210f96 100644 (file)
@@ -132,6 +132,17 @@ inline std::string BytecodeReader::read_str() {
   return std::string((char*)OldAt, Size);
 }
 
+void BytecodeReader::read_str(SmallVectorImpl<char> &StrData) {
+  StrData.clear();
+  unsigned Size = read_vbr_uint();
+  const unsigned char *OldAt = At;
+  At += Size;
+  if (At > BlockEnd)             // Size invalid?
+    error("Ran out of data reading a string!");
+  StrData.append(OldAt, At);
+}
+
+
 /// Read an arbitrary block of data
 inline void BytecodeReader::read_data(void *Ptr, void *End) {
   unsigned char *Start = (unsigned char *)Ptr;
@@ -943,6 +954,8 @@ void BytecodeReader::ParseValueSymbolTable(Function *CurrentFunction,
            E = CurrentFunction->end(); I != E; ++I)
       BBMap.push_back(I);
 
+  SmallVector<char, 32> NameStr;
+  
   while (moreInBlock()) {
     // Symtab block header: [num entries][type id number]
     unsigned NumEntries = read_vbr_uint();
@@ -951,19 +964,22 @@ void BytecodeReader::ParseValueSymbolTable(Function *CurrentFunction,
     for (unsigned i = 0; i != NumEntries; ++i) {
       // Symtab entry: [def slot #][name]
       unsigned slot = read_vbr_uint();
-      std::string Name = read_str();
+      read_str(NameStr);
       Value *V = 0;
       if (Typ == LabelTySlot) {
-        if (slot < BBMap.size())
-          V = BBMap[slot];
+        V = (slot < BBMap.size()) ? BBMap[slot] : 0;
       } else {
-        V = getValue(Typ, slot, false); // Find mapping...
+        V = getValue(Typ, slot, false); // Find mapping.
       }
-      if (Handler) Handler->handleSymbolTableValue(Typ, slot, Name);
+      if (Handler) Handler->handleSymbolTableValue(Typ, slot,
+                                                   &NameStr[0], NameStr.size());
       if (V == 0)
-        error("Failed value look-up for name '" + Name + "', type #" + 
+        error("Failed value look-up for name '" + 
+              std::string(NameStr.begin(), NameStr.end()) + "', type #" + 
               utostr(Typ) + " slot #" + utostr(slot));
-      V->setName(Name);
+      V->setName(&NameStr[0], NameStr.size());
+      
+      NameStr.clear();
     }
   }
   checkPastBlockEnd("Symbol Table");
index 8acf6c042f8ebc3f6923fd3c4bbda47419148d4e..ca966f1cc7489b6483aa15ccb4ad4ded227ef49c 100644 (file)
@@ -438,6 +438,7 @@ private:
 
   /// @brief Read a string
   inline std::string read_str();
+  inline void read_str(SmallVectorImpl<char> &StrData);
 
   /// @brief Read a float value
   inline void read_float(float& FloatVal);