r343224 - [Tooling] Get rid of uses of llvm::Twine::str which is slow. NFC
David Blaikie via cfe-commits
cfe-commits at lists.llvm.org
Mon Oct 1 09:45:33 PDT 2018
On Thu, Sep 27, 2018 at 7:51 AM Eric Liu via cfe-commits <
cfe-commits at lists.llvm.org> wrote:
> Author: ioeric
> Date: Thu Sep 27 07:50:24 2018
> New Revision: 343224
>
> URL: http://llvm.org/viewvc/llvm-project?rev=343224&view=rev
> Log:
> [Tooling] Get rid of uses of llvm::Twine::str which is slow. NFC
>
> Modified:
> cfe/trunk/lib/Tooling/Inclusions/HeaderIncludes.cpp
>
> Modified: cfe/trunk/lib/Tooling/Inclusions/HeaderIncludes.cpp
> URL:
> http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Tooling/Inclusions/HeaderIncludes.cpp?rev=343224&r1=343223&r2=343224&view=diff
>
> ==============================================================================
> --- cfe/trunk/lib/Tooling/Inclusions/HeaderIncludes.cpp (original)
> +++ cfe/trunk/lib/Tooling/Inclusions/HeaderIncludes.cpp Thu Sep 27
> 07:50:24 2018
> @@ -10,6 +10,7 @@
> #include "clang/Tooling/Inclusions/HeaderIncludes.h"
> #include "clang/Basic/SourceManager.h"
> #include "clang/Lex/Lexer.h"
> +#include "llvm/Support/FormatVariadic.h"
>
> namespace clang {
> namespace tooling {
> @@ -181,7 +182,7 @@ bool IncludeCategoryManager::isMainHeade
> llvm::sys::path::stem(IncludeName.drop_front(1).drop_back(1));
> if (FileStem.startswith(HeaderStem) ||
> FileStem.startswith_lower(HeaderStem)) {
> - llvm::Regex MainIncludeRegex((HeaderStem +
> Style.IncludeIsMainRegex).str(),
> + llvm::Regex MainIncludeRegex(HeaderStem.str() +
> Style.IncludeIsMainRegex,
> llvm::Regex::IgnoreCase);
> if (MainIncludeRegex.match(FileStem))
> return true;
> @@ -275,8 +276,8 @@ HeaderIncludes::insert(llvm::StringRef I
> if ((IsAngled && StringRef(Inc.Name).startswith("<")) ||
> (!IsAngled && StringRef(Inc.Name).startswith("\"")))
> return llvm::None;
> - std::string Quoted = IsAngled ? ("<" + IncludeName + ">").str()
> - : ("\"" + IncludeName + "\"").str();
> + std::string Quoted =
> + llvm::formatv(IsAngled ? "<{0}>" : "\"{0}\"", IncludeName);
> StringRef QuotedName = Quoted;
> int Priority = Categories.getIncludePriority(
> QuotedName, /*CheckMainHeader=*/FirstIncludeOffset < 0);
> @@ -293,7 +294,7 @@ HeaderIncludes::insert(llvm::StringRef I
> }
> }
> assert(InsertOffset <= Code.size());
> - std::string NewInclude = ("#include " + QuotedName + "\n").str();
> + std::string NewInclude = llvm::formatv("#include {0}\n", QuotedName);
>
Any idea why formatv is performing better here? Might be worth some
consideration/fixing op+.
> // When inserting headers at end of the code, also append '\n' to the
> code
> // if it does not end with '\n'.
> // FIXME: when inserting multiple #includes at the end of code, only one
>
>
> _______________________________________________
> cfe-commits mailing list
> cfe-commits at lists.llvm.org
> http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20181001/8f8aae05/attachment.html>
More information about the cfe-commits
mailing list