forked from OSchip/llvm-project
Rewriter: Output RewriteRope contents efficiently
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. llvm-svn: 196119
This commit is contained in:
parent
a26fcc7989
commit
d505d40360
|
@ -14,6 +14,7 @@
|
|||
#ifndef LLVM_CLANG_REWRITEROPE_H
|
||||
#define LLVM_CLANG_REWRITEROPE_H
|
||||
|
||||
#include "llvm/ADT/StringRef.h"
|
||||
#include "llvm/Support/Compiler.h"
|
||||
#include <cassert>
|
||||
#include <cstddef>
|
||||
|
@ -144,7 +145,11 @@ namespace clang {
|
|||
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();
|
||||
};
|
||||
|
||||
|
|
|
@ -26,8 +26,11 @@
|
|||
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;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue