[clang] clang-format: Sort includes by stem rather than full filename (PR #137840)

Björn Schäpers via cfe-commits cfe-commits at lists.llvm.org
Tue Apr 29 11:51:09 PDT 2025


================
@@ -3219,17 +3219,19 @@ static void sortCppIncludes(const FormatStyle &Style,
 
   if (Style.SortIncludes == FormatStyle::SI_CaseInsensitive) {
     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);
+      const auto LHSStem = llvm::sys::path::stem(Includes[LHSI].Filename);
+      const auto RHSStem = llvm::sys::path::stem(Includes[RHSI].Filename);
----------------
HazardyKnusperkeks wrote:

This two lines can be moved out of the `if` and `else`.

https://github.com/llvm/llvm-project/pull/137840


More information about the cfe-commits mailing list