[PDB] Fix quadratic behavior when writing a BinaryItemStream
Binary streams are an abstraction over a discontiguous buffer. To write a discontiguous buffer, we want to copy each contiguous chunk individually. Currently BinaryStreams do not expose a way to iterate over the chunks, so the code repeatedly calls readLongestContiguousChunk() with an increasing offset. In order to lookup the chunk by offset, we would iterate the items list to figure out which chunk the offset is within. This is obviously O(n^2). Instead, pre-compute a table of offsets and do a binary search to figure out which chunk to use. This is still only an O(n^2) to O(n log n) improvement, but it's a very local fix that seems worth doing. This improves self-linking lld.exe with PDBs from 90s to 10s. llvm-svn: 307970
Loading
Please register or sign in to comment