Skip to content
This repository was archived by the owner on Dec 15, 2022. It is now read-only.

Commit 10f4003

Browse files
committed
use a locale-independent comparison
has slightly better performance, and is more stable (since it doesn't rely upon the configured locale)
1 parent 891167a commit 10f4003

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

lib/sort-lines.coffee

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,19 +28,22 @@ sortTextLines = (editor, sorter) ->
2828

2929
sortLines = (editor) ->
3030
sortTextLines editor, (textLines) ->
31-
textLines.sort (a, b) -> a.localeCompare(b)
31+
textLines.sort (a, b) -> if a is b then 0 else if a > b then 1 else -1
3232

3333
sortLinesReversed = (editor) ->
3434
sortTextLines editor, (textLines) ->
35-
textLines.sort (a, b) -> b.localeCompare(a)
35+
textLines.sort (a, b) -> if a is b then 0 else if a < b then 1 else -1
3636

3737
uniqueLines = (editor) ->
3838
sortTextLines editor, (textLines) ->
3939
textLines.filter (value, index, self) -> self.indexOf(value) == index
4040

4141
sortLinesInsensitive = (editor) ->
4242
sortTextLines editor, (textLines) ->
43-
textLines.sort (a, b) -> a.toLowerCase().localeCompare(b.toLowerCase())
43+
textLines.sort (a, b) ->
44+
a = a.toLowerCase()
45+
b = b.toLowerCase()
46+
if a is b then 0 else if a > b then 1 else -1
4447

4548
sortLinesNatural = (editor) ->
4649
sortTextLines editor, (textLines) ->

0 commit comments

Comments
 (0)