aboutsummaryrefslogtreecommitdiff
path: root/Rewrite/Rewriter.cpp
diff options
context:
space:
mode:
authorChris Lattner <sabre@nondot.org>2007-11-08 07:35:14 +0000
committerChris Lattner <sabre@nondot.org>2007-11-08 07:35:14 +0000
commit8b0c2f659d350118cceee33c211a3dd5e3138ac2 (patch)
treee5802c3996fc1c9c70339c8ae65cc9f023ffef3c /Rewrite/Rewriter.cpp
parentcdd808e2af9f92ef406065c4855ac72d121dbcda (diff)
Add a new RewriteRope data structure which is a smarter way to represent the text
backing a rewrite buffer than using an std::vector<char>. This class was hacked together very quickly and needs to be cleaned up, but it seems to work. It speeds up rewriting a a 7M file from 6.43s to 0.24s on my machine. The impl could also be made to be a lot more algorithmically sound. This produces identical output to using vector on this testcase, if it causes a problems or bugs are encountered, it can be disabled by changing the RewriteBuffer::Buffer typedef back. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@43884 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'Rewrite/Rewriter.cpp')
-rw-r--r--Rewrite/Rewriter.cpp5
1 files changed, 5 insertions, 0 deletions
diff --git a/Rewrite/Rewriter.cpp b/Rewrite/Rewriter.cpp
index 1df169ac84..3a007f3e71 100644
--- a/Rewrite/Rewriter.cpp
+++ b/Rewrite/Rewriter.cpp
@@ -120,6 +120,11 @@ void RewriteBuffer::ReplaceText(unsigned OrigOffset, unsigned OrigLength,
unsigned RealOffset = getMappedOffset(OrigOffset, true);
assert(RealOffset+OrigLength <= Buffer.size() && "Invalid location");
+ Buffer.erase(Buffer.begin()+RealOffset, Buffer.begin()+RealOffset+OrigLength);
+ Buffer.insert(Buffer.begin()+RealOffset, NewStr, NewStr+NewLength);
+ AddDelta(OrigOffset, NewLength-OrigLength);
+ return;
+
// Overwrite the common piece.
unsigned CommonLength = std::min(OrigLength, NewLength);
std::copy(NewStr, NewStr+CommonLength, Buffer.begin()+RealOffset);