Skip to content

Commit e9caed5

Browse files
committed
shorted and 3x faster version
1 parent 19ca701 commit e9caed5

File tree

1 file changed

+5
-21
lines changed

1 file changed

+5
-21
lines changed

sorted.go

Lines changed: 5 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -5,26 +5,10 @@ import (
55
"sort"
66
)
77

8-
type i18nStruct struct {
9-
lang string
10-
arr []string
11-
}
12-
13-
func (i18n i18nStruct) Less(i, j int) bool {
14-
less := collate.IndexString(i18n.lang)
15-
return less(i18n.arr[i], i18n.arr[j])
16-
}
17-
18-
func (i18n i18nStruct) Len() int {
19-
return len(i18n.arr)
20-
}
21-
22-
func (i18n i18nStruct) Swap(i, j int) {
23-
i18n.arr[i], i18n.arr[j] = i18n.arr[j], i18n.arr[i]
24-
}
25-
268
func sorted(arr []string, lang string) []string {
27-
i18n := i18nStruct{lang, arr}
28-
sort.Sort(i18n)
29-
return i18n.arr
9+
less := collate.IndexString(lang)
10+
sort.SliceStable(arr, func(i, j int) bool {
11+
return less(arr[i], arr[j])
12+
})
13+
return arr
3014
}

0 commit comments

Comments
 (0)