[PATCH] D144708: [clangd] Fix UB in scanPreamble
Haojian Wu via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Fri Feb 24 01:12:17 PST 2023
hokein accepted this revision.
hokein added inline comments.
This revision is now accepted and ready to land.
================
Comment at: clang-tools-extra/clangd/Preamble.cpp:351
auto PreambleContents =
- llvm::MemoryBuffer::getMemBufferCopy(Contents.substr(0, Bounds.Size));
+ llvm::MemoryBuffer::getMemBufferCopy(PI.Contents.substr(0, Bounds.Size));
auto Clang = prepareCompilerInstance(
----------------
Looks like we have an extra cost here -- the std::string.substr will construct a new string everytime, we could save it by using `llvm::StringRef(PI.Contents).substr(0, Bounds.Size)`.
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D144708/new/
https://reviews.llvm.org/D144708
More information about the cfe-commits
mailing list