[clang-tools-extra] r253929 - Fix test failure introduced by r253859. I believe that the new behavior
Daniel Jasper via cfe-commits
cfe-commits at lists.llvm.org
Mon Nov 23 14:28:56 PST 2015
Author: djasper
Date: Mon Nov 23 16:28:56 2015
New Revision: 253929
URL: http://llvm.org/viewvc/llvm-project?rev=253929&view=rev
Log:
Fix test failure introduced by r253859. I believe that the new behavior
in r253859 makes sense in many cases and thus, I have fixed the
implementation of calculateChangedRanges instead. It had a FIXME anyway
saying that it was unecessarily using shiftedCodePosition which
resulted in O(N^2) runtime.
Modified:
clang-tools-extra/trunk/clang-apply-replacements/lib/Tooling/ApplyReplacements.cpp
Modified: clang-tools-extra/trunk/clang-apply-replacements/lib/Tooling/ApplyReplacements.cpp
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-apply-replacements/lib/Tooling/ApplyReplacements.cpp?rev=253929&r1=253928&r2=253929&view=diff
==============================================================================
--- clang-tools-extra/trunk/clang-apply-replacements/lib/Tooling/ApplyReplacements.cpp (original)
+++ clang-tools-extra/trunk/clang-apply-replacements/lib/Tooling/ApplyReplacements.cpp Mon Nov 23 16:28:56 2015
@@ -209,14 +209,11 @@ RangeVector calculateChangedRanges(
RangeVector ChangedRanges;
// Generate the new ranges from the replacements.
- //
- // NOTE: This is O(n^2) in the number of replacements. If this starts to
- // become a problem inline shiftedCodePosition() here and do shifts in a
- // single run through this loop.
+ int Shift = 0;
for (const tooling::Replacement &R : Replaces) {
- unsigned Offset = tooling::shiftedCodePosition(Replaces, R.getOffset());
+ unsigned Offset = R.getOffset() + Shift;
unsigned Length = R.getReplacementText().size();
-
+ Shift += Length - R.getLength();
ChangedRanges.push_back(tooling::Range(Offset, Length));
}
More information about the cfe-commits
mailing list