================ @@ -3221,15 +3223,33 @@ static void sortCppIncludes(const FormatStyle &Style, stable_sort(Indices, [&](unsigned LHSI, unsigned RHSI) { const auto LHSFilenameLower = Includes[LHSI].Filename.lower(); const auto RHSFilenameLower = Includes[RHSI].Filename.lower(); - return std::tie(Includes[LHSI].Priority, LHSFilenameLower, - Includes[LHSI].Filename) < - std::tie(Includes[RHSI].Priority, RHSFilenameLower, - Includes[RHSI].Filename); + SmallString<128> LHSStem = Includes[LHSI].Filename; + SmallString<128> RHSStem = Includes[RHSI].Filename; + if (Style.IncludeStyle.IncludeSortKey == + tooling::IncludeStyle::ISK_Stem) { + llvm::sys::path::replace_extension(LHSStem, ""); + llvm::sys::path::replace_extension(RHSStem, ""); + } + const auto LHSStemLower = LHSStem.str().lower(); + const auto RHSStemLower = RHSStem.str().lower(); + return std::tie(Includes[LHSI].Priority, LHSStemLower, LHSStem, + LHSFilenameLower, Includes[LHSI].Filename) < + std::tie(Includes[RHSI].Priority, RHSStemLower, RHSStem, + RHSFilenameLower, Includes[RHSI].Filename); }); } else { stable_sort(Indices, [&](unsigned LHSI, unsigned RHSI) { - return std::tie(Includes[LHSI].Priority, Includes[LHSI].Filename) < - std::tie(Includes[RHSI].Priority, Includes[RHSI].Filename); + SmallString<128> LHSStem = Includes[LHSI].Filename; + SmallString<128> RHSStem = Includes[RHSI].Filename; + if (Style.IncludeStyle.IncludeSortKey == + tooling::IncludeStyle::ISK_Stem) { + llvm::sys::path::replace_extension(LHSStem, ""); + llvm::sys::path::replace_extension(RHSStem, ""); + } + return std::tie(Includes[LHSI].Priority, LHSStem, + Includes[LHSI].Filename) < + std::tie(Includes[RHSI].Priority, RHSStem, + Includes[RHSI].Filename); ---------------- owenca wrote:
There's a little too much duplication now. Can you simplify/extract/combine this part? https://github.com/llvm/llvm-project/pull/137840 _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits