llvm.org GIT mirror llvm / 1736df6
Simplify the raw_svector_ostream tweak from r212816 The memcpy() and overlap helps didn't help much with timings, so clean up the change. The difference at this point is that we now leave growth of the storage buffer up to SmallVector's implementation: - OS.reserve(OS.capacity() * 2); + OS.reserve(OS.size() + 64); git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@212837 91177308-0d34-0410-b5e6-96231b3b80d8 Alp Toker 5 years ago
1 changed file(s) with 6 addition(s) and 15 deletion(s). Raw diff Collapse all Expand all
728728 }
729729
730730 void raw_svector_ostream::write_impl(const char *Ptr, size_t Size) {
731 size_t NewSize = OS.size() + Size;
732 size_t NewReservation = NewSize + 64;
733
734 bool NoOverlap = Ptr + Size < OS.begin() || Ptr > OS.begin() + OS.capacity();
735
736 if (NoOverlap) {
737 assert(!GetNumBytesInBuffer());
738 OS.reserve(NewReservation);
739 memcpy(OS.end(), Ptr, Size);
740 OS.set_size(NewSize);
741 } else if (Ptr == OS.end()) {
731 if (Ptr == OS.end()) {
742732 // Grow the buffer to include the scratch area without copying.
733 size_t NewSize = OS.size() + Size;
743734 assert(NewSize <= OS.capacity() && "Invalid write_impl() call!");
744735 OS.set_size(NewSize);
745 OS.reserve(NewReservation);
746736 } else {
737 assert(!GetNumBytesInBuffer());
747738 OS.append(Ptr, Ptr + Size);
748 OS.reserve(NewReservation);
749 }
750
739 }
740
741 OS.reserve(OS.size() + 64);
751742 SetBuffer(OS.end(), OS.capacity() - OS.size());
752743 }
753744