This avoids allocation of temporary std::strings for file contents, instead
writing chunks directly to the output stream.
The old character-based B-tree iterator remains intact for the time being.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@196119
91177308-0d34-0410-b5e6-
96231b3b80d8
#ifndef LLVM_CLANG_REWRITEROPE_H
#define LLVM_CLANG_REWRITEROPE_H
+#include "llvm/ADT/StringRef.h"
#include "llvm/Support/Compiler.h"
#include <cassert>
#include <cstddef>
inline RopePieceBTreeIterator operator++(int) { // Postincrement
RopePieceBTreeIterator tmp = *this; ++*this; return tmp;
}
- private:
+
+ llvm::StringRef piece() const {
+ return llvm::StringRef(&(*CurPiece)[0], CurPiece->size());
+ }
+
void MoveToNextPiece();
};
using namespace clang;
raw_ostream &RewriteBuffer::write(raw_ostream &os) const {
- // FIXME: eliminate the copy by writing out each chunk at a time
- os << std::string(begin(), end());
+ // Walk RewriteRope chunks efficiently using MoveToNextPiece() instead of the
+ // character iterator.
+ for (RopePieceBTreeIterator I = begin(), E = end(); I != E;
+ I.MoveToNextPiece())
+ os << I.piece();
return os;
}