Author: mprobst Date: Sat Jul 9 10:11:18 2016 New Revision: 274977 URL: http://llvm.org/viewvc/llvm-project?rev=274977&view=rev Log: clang-format: [JS] Sort imports case insensitive.
Summary: ASCII case sorting does not help finding imported symbols quickly, and it is common to have e.g. class Foo and function fooFactory exported/imported from the same file. Reviewers: djasper Subscribers: klimek, cfe-commits Differential Revision: http://reviews.llvm.org/D22146 Modified: cfe/trunk/lib/Format/SortJavaScriptImports.cpp cfe/trunk/unittests/Format/SortImportsTestJS.cpp Modified: cfe/trunk/lib/Format/SortJavaScriptImports.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Format/SortJavaScriptImports.cpp?rev=274977&r1=274976&r2=274977&view=diff ============================================================================== --- cfe/trunk/lib/Format/SortJavaScriptImports.cpp (original) +++ cfe/trunk/lib/Format/SortJavaScriptImports.cpp Sat Jul 9 10:11:18 2016 @@ -105,8 +105,8 @@ bool operator<(const JsModuleReference & // Empty URLs sort *last* (for export {...};). if (LHS.URL.empty() != RHS.URL.empty()) return LHS.URL.empty() < RHS.URL.empty(); - if (LHS.URL != RHS.URL) - return LHS.URL < RHS.URL; + if (int Res = LHS.URL.compare_lower(RHS.URL)) + return Res < 0; // '*' imports (with prefix) sort before {a, b, ...} imports. if (LHS.Prefix.empty() != RHS.Prefix.empty()) return LHS.Prefix.empty() < RHS.Prefix.empty(); @@ -245,7 +245,7 @@ private: std::stable_sort( Symbols.begin(), Symbols.end(), [&](const JsImportedSymbol &LHS, const JsImportedSymbol &RHS) { - return LHS.Symbol < RHS.Symbol; + return LHS.Symbol.compare_lower(RHS.Symbol) < 0; }); if (Symbols == Reference.Symbols) { // No change in symbol order. Modified: cfe/trunk/unittests/Format/SortImportsTestJS.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/Format/SortImportsTestJS.cpp?rev=274977&r1=274976&r2=274977&view=diff ============================================================================== --- cfe/trunk/unittests/Format/SortImportsTestJS.cpp (original) +++ cfe/trunk/unittests/Format/SortImportsTestJS.cpp Sat Jul 9 10:11:18 2016 @@ -240,6 +240,27 @@ TEST_F(SortImportsTestJS, TrailingComma) verifySort("import {A, B,} from 'aa';\n", "import {B, A,} from 'aa';\n"); } +TEST_F(SortImportsTestJS, SortCaseInsensitive) { + verifySort("import {A} from 'aa';\n" + "import {A} from 'Ab';\n" + "import {A} from 'b';\n" + "import {A} from 'Bc';\n" + "\n" + "1;", + "import {A} from 'b';\n" + "import {A} from 'Bc';\n" + "import {A} from 'Ab';\n" + "import {A} from 'aa';\n" + "\n" + "1;"); + verifySort("import {aa, Ab, b, Bc} from 'x';\n" + "\n" + "1;", + "import {b, Bc, Ab, aa} from 'x';\n" + "\n" + "1;"); +} + } // end namespace } // end namespace format } // end namespace clang _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits