From: Chris Lattner Date: Mon, 21 Jan 2013 18:24:49 +0000 (+0000) Subject: Fix a heinous inefficiency introduced in r149918, wherein reading each byte of a X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=1aeca1e8069ac5ff6c4e6ba35e7e1550d760461e;p=platform%2Fupstream%2Fllvm.git Fix a heinous inefficiency introduced in r149918, wherein reading each byte of a BLOB (i.e., large, performance intensive data) in a bitcode file was switched to invoking one virtual method call per byte read. Now we do one virtual call per BLOB. llvm-svn: 173065 --- diff --git a/llvm/include/llvm/Bitcode/BitstreamReader.h b/llvm/include/llvm/Bitcode/BitstreamReader.h index 16f9686..c143886 100644 --- a/llvm/include/llvm/Bitcode/BitstreamReader.h +++ b/llvm/include/llvm/Bitcode/BitstreamReader.h @@ -237,12 +237,6 @@ public: static_cast(pos - 1)); } - unsigned char getByte(size_t pos) { - uint8_t byte = -1; - BitStream->getBitcodeBytes().readByte(pos, &byte); - return byte; - } - uint32_t getWord(size_t pos) { uint8_t buf[4] = { 0xFF, 0xFF, 0xFF, 0xFF }; BitStream->getBitcodeBytes().readBytes(pos, sizeof(buf), buf, NULL); diff --git a/llvm/lib/Bitcode/Reader/BitstreamReader.cpp b/llvm/lib/Bitcode/Reader/BitstreamReader.cpp index 92133bb..7984512 100644 --- a/llvm/lib/Bitcode/Reader/BitstreamReader.cpp +++ b/llvm/lib/Bitcode/Reader/BitstreamReader.cpp @@ -255,18 +255,17 @@ unsigned BitstreamCursor::readRecord(unsigned AbbrevID, break; } - // Otherwise, read the number of bytes. If we can return a reference to - // the data, do so to avoid copying it. + // Otherwise, inform the streamer that we need these bytes in memory. + const char *Ptr = (const char*) + BitStream->getBitcodeBytes().getPointer(CurBitPos/8, NumElts); + + // If we can return a reference to the data, do so to avoid copying it. if (Blob) { - *Blob = - StringRef((const char*)BitStream->getBitcodeBytes().getPointer( - CurBitPos/8, NumElts), - NumElts); + *Blob = StringRef(Ptr, NumElts); } else { - // FIXME: This is a brutally inefficient way to do this. Why isn't this - // just using getPointer? + // Otherwise, unpack into Vals with zero extension. for (; NumElts; --NumElts) - Vals.push_back(Read(8)); + Vals.push_back((unsigned char)*Ptr++); } // Skip over tail padding. JumpToBit(NewEnd);