OSDN Git Service

Make BinaryStreamReader::readCString a bit faster.
authorZachary Turner <zturner@google.com>
Thu, 25 May 2017 21:12:27 +0000 (21:12 +0000)
committerZachary Turner <zturner@google.com>
Thu, 25 May 2017 21:12:27 +0000 (21:12 +0000)
commit7814846d2dbc9bdc87155c9376b5f7c3d1baa90d
tree577c7721b7723a7c6d18c796a5756191e9637957
parentae12b7b36034f0ce05b80326d78205f52b1dd35c
Make BinaryStreamReader::readCString a bit faster.

Previously it would do a character by character search for a null
terminator, to account for the fact that an arbitrary stream need not
store its data contiguously so you couldn't just do a memchr. However, the
stream API has a function which will return the longest contiguous chunk
without doing a copy, and by using this function we can do a memchr on the
individual chunks. For certain types of streams like data from object
files etc, this is guaranteed to find the null terminator with only a
single memchr, but even with discontiguous streams such as
MappedBlockStream, it's rare that any given string will cross a block
boundary, so even those will almost always be satisfied with a single
memchr.

This optimization is worth a 10-12% reduction in link time (4.2 seconds ->
3.75 seconds)

Differential Revision: https://reviews.llvm.org/D33503

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@303918 91177308-0d34-0410-b5e6-96231b3b80d8
lib/Support/BinaryStreamReader.cpp