[llvm-commits] [llvm] r151750 - in /llvm/trunk: include/llvm/Bitcode/BitstreamWriter.h lib/Bitcode/Writer/BitcodeWriter.cpp

Daniel Dunbar daniel at zuster.org
Wed Feb 29 12:31:09 PST 2012


Author: ddunbar
Date: Wed Feb 29 14:31:09 2012
New Revision: 151750

URL: http://llvm.org/viewvc/llvm-project?rev=151750&view=rev
Log:
BitstreamWriter: Change primary output buffer to be a SmallVector instead of an
std::vector.
 - Good for 1-2% speedup on writing PCH for Cocoa.h.
 - Clang side API match to follow shortly, there wasn't an easy way to make this
   non-breaking.

Modified:
    llvm/trunk/include/llvm/Bitcode/BitstreamWriter.h
    llvm/trunk/lib/Bitcode/Writer/BitcodeWriter.cpp

Modified: llvm/trunk/include/llvm/Bitcode/BitstreamWriter.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Bitcode/BitstreamWriter.h?rev=151750&r1=151749&r2=151750&view=diff
==============================================================================
--- llvm/trunk/include/llvm/Bitcode/BitstreamWriter.h (original)
+++ llvm/trunk/include/llvm/Bitcode/BitstreamWriter.h Wed Feb 29 14:31:09 2012
@@ -16,13 +16,14 @@
 #define BITSTREAM_WRITER_H
 
 #include "llvm/ADT/StringRef.h"
+#include "llvm/ADT/SmallVector.h"
 #include "llvm/Bitcode/BitCodes.h"
 #include <vector>
 
 namespace llvm {
 
 class BitstreamWriter {
-  std::vector<unsigned char> &Out;
+  SmallVectorImpl<char> &Out;
 
   /// CurBit - Always between 0 and 31 inclusive, specifies the next bit to use.
   unsigned CurBit;
@@ -90,7 +91,7 @@
   }
 
 public:
-  explicit BitstreamWriter(std::vector<unsigned char> &O)
+  explicit BitstreamWriter(SmallVectorImpl<char> &O)
     : Out(O), CurBit(0), CurValue(0), CurCodeSize(2) {}
 
   ~BitstreamWriter() {

Modified: llvm/trunk/lib/Bitcode/Writer/BitcodeWriter.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Bitcode/Writer/BitcodeWriter.cpp?rev=151750&r1=151749&r2=151750&view=diff
==============================================================================
--- llvm/trunk/lib/Bitcode/Writer/BitcodeWriter.cpp (original)
+++ llvm/trunk/lib/Bitcode/Writer/BitcodeWriter.cpp Wed Feb 29 14:31:09 2012
@@ -1774,8 +1774,7 @@
   DarwinBCHeaderSize = 5*4
 };
 
-static void WriteInt32ToBuffer(uint32_t Value,
-                               std::vector<unsigned char> &Buffer,
+static void WriteInt32ToBuffer(uint32_t Value, SmallVectorImpl<char> &Buffer,
                                uint32_t &Position) {
   Buffer[Position + 0] = (unsigned char) (Value >>  0);
   Buffer[Position + 1] = (unsigned char) (Value >>  8);
@@ -1784,7 +1783,7 @@
   Position += 4;
 }
 
-static void EmitDarwinBCHeaderAndTrailer(std::vector<unsigned char> &Buffer,
+static void EmitDarwinBCHeaderAndTrailer(SmallVectorImpl<char> &Buffer,
                                          const Triple &TT) {
   unsigned CPUType = ~0U;
 
@@ -1833,7 +1832,7 @@
 /// WriteBitcodeToFile - Write the specified module to the specified output
 /// stream.
 void llvm::WriteBitcodeToFile(const Module *M, raw_ostream &Out) {
-  std::vector<unsigned char> Buffer;
+  SmallVector<char, 1024> Buffer;
   Buffer.reserve(256*1024);
 
   // If this is darwin or another generic macho target, reserve space for the





More information about the llvm-commits mailing list