Author: Nathan James Date: 2021-03-09T21:39:23Z New Revision: c92d2ea59e79fb366512e16eb1209f2de3ed6ff1
URL: https://github.com/llvm/llvm-project/commit/c92d2ea59e79fb366512e16eb1209f2de3ed6ff1 DIFF: https://github.com/llvm/llvm-project/commit/c92d2ea59e79fb366512e16eb1209f2de3ed6ff1.diff LOG: [clangd][NFC] Use std::string::replace in SourceCode:applyChange. Just looks nicer and easier to read. Reviewed By: kadircet Differential Revision: https://reviews.llvm.org/D98274 Added: Modified: clang-tools-extra/clangd/SourceCode.cpp Removed: ################################################################################ diff --git a/clang-tools-extra/clangd/SourceCode.cpp b/clang-tools-extra/clangd/SourceCode.cpp index 14cde561474e..8faed3e046aa 100644 --- a/clang-tools-extra/clangd/SourceCode.cpp +++ b/clang-tools-extra/clangd/SourceCode.cpp @@ -1091,15 +1091,8 @@ llvm::Error applyChange(std::string &Contents, "computed range length ({1}).", *Change.rangeLength, ComputedRangeLength); - std::string NewContents; - NewContents.reserve(*StartIndex + Change.text.length() + - (Contents.length() - *EndIndex)); + Contents.replace(*StartIndex, *EndIndex - *StartIndex, Change.text); - NewContents = Contents.substr(0, *StartIndex); - NewContents += Change.text; - NewContents += Contents.substr(*EndIndex); - - std::swap(Contents, NewContents); return llvm::Error::success(); } _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits