From acbceeae4d7bdfbbc3437c60a5a3e26449888a15 Mon Sep 17 00:00:00 2001 From: Daniel Dunbar Date: Wed, 29 Feb 2012 20:31:09 +0000 Subject: [PATCH] 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. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@151750 91177308-0d34-0410-b5e6-96231b3b80d8 --- include/llvm/Bitcode/BitstreamWriter.h | 5 +++-- lib/Bitcode/Writer/BitcodeWriter.cpp | 7 +++---- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/include/llvm/Bitcode/BitstreamWriter.h b/include/llvm/Bitcode/BitstreamWriter.h index 56b20c8474a..55e3cd390b1 100644 --- a/include/llvm/Bitcode/BitstreamWriter.h +++ b/include/llvm/Bitcode/BitstreamWriter.h @@ -16,13 +16,14 @@ #define BITSTREAM_WRITER_H #include "llvm/ADT/StringRef.h" +#include "llvm/ADT/SmallVector.h" #include "llvm/Bitcode/BitCodes.h" #include namespace llvm { class BitstreamWriter { - std::vector &Out; + SmallVectorImpl &Out; /// CurBit - Always between 0 and 31 inclusive, specifies the next bit to use. unsigned CurBit; @@ -90,7 +91,7 @@ class BitstreamWriter { } public: - explicit BitstreamWriter(std::vector &O) + explicit BitstreamWriter(SmallVectorImpl &O) : Out(O), CurBit(0), CurValue(0), CurCodeSize(2) {} ~BitstreamWriter() { diff --git a/lib/Bitcode/Writer/BitcodeWriter.cpp b/lib/Bitcode/Writer/BitcodeWriter.cpp index c6c7fb7dcb2..93769906801 100644 --- a/lib/Bitcode/Writer/BitcodeWriter.cpp +++ b/lib/Bitcode/Writer/BitcodeWriter.cpp @@ -1774,8 +1774,7 @@ enum { DarwinBCHeaderSize = 5*4 }; -static void WriteInt32ToBuffer(uint32_t Value, - std::vector &Buffer, +static void WriteInt32ToBuffer(uint32_t Value, SmallVectorImpl &Buffer, uint32_t &Position) { Buffer[Position + 0] = (unsigned char) (Value >> 0); Buffer[Position + 1] = (unsigned char) (Value >> 8); @@ -1784,7 +1783,7 @@ static void WriteInt32ToBuffer(uint32_t Value, Position += 4; } -static void EmitDarwinBCHeaderAndTrailer(std::vector &Buffer, +static void EmitDarwinBCHeaderAndTrailer(SmallVectorImpl &Buffer, const Triple &TT) { unsigned CPUType = ~0U; @@ -1833,7 +1832,7 @@ static void EmitDarwinBCHeaderAndTrailer(std::vector &Buffer, /// WriteBitcodeToFile - Write the specified module to the specified output /// stream. void llvm::WriteBitcodeToFile(const Module *M, raw_ostream &Out) { - std::vector Buffer; + SmallVector Buffer; Buffer.reserve(256*1024); // If this is darwin or another generic macho target, reserve space for the