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

Commit da132cd

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 1b29f15 commit da132cd

1 file changed

Lines changed: 6 additions & 3 deletions

File tree

lib/sort-lines.coffee

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

2626
sortLines = (editor) ->
2727
sortTextLines editor, (textLines) ->
28-
textLines.sort (a, b) -> a.localeCompare(b)
28+
textLines.sort (a, b) -> if a is b then 0 else if a > b then 1 else -1
2929

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

3434
uniqueLines = (editor) ->
3535
sortTextLines editor, (textLines) ->
3636
textLines.filter (value, index, self) -> self.indexOf(value) == index
3737

3838
sortLinesInsensitive = (editor) ->
3939
sortTextLines editor, (textLines) ->
40-
textLines.sort (a, b) -> a.toLowerCase().localeCompare(b.toLowerCase())
40+
textLines.sort (a, b) ->
41+
a = a.toLowerCase()
42+
b = b.toLowerCase()
43+
if a is b then 0 else if a > b then 1 else -1

0 commit comments

Comments
 (0)