Commit 5afa271c authored by Marcel van Lohuizen's avatar Marcel van Lohuizen

exp/locale/collate: several changes based on comments on CL 7060051

which was submitted earlier.

R=r
CC=golang-dev
https://golang.org/cl/7402048
parent f853e9aa
...@@ -35,15 +35,6 @@ func (s *sorter) init(n int) { ...@@ -35,15 +35,6 @@ func (s *sorter) init(n int) {
s.keys = s.keys[0:n] s.keys = s.keys[0:n]
} }
func (s *sorter) clean() {
if len(s.buf.key) > maxSortBuffer {
s.buf.key = s.buf.buf[:0]
}
if len(s.keys) > maxSortEntries {
s.keys = nil
}
}
func (s *sorter) sort(src swapper) { func (s *sorter) sort(src swapper) {
s.src = src s.src = src
sort.Sort(s) sort.Sort(s)
...@@ -80,8 +71,8 @@ func (c *Collator) Sort(x Lister) { ...@@ -80,8 +71,8 @@ func (c *Collator) Sort(x Lister) {
c.sorter.sort(x) c.sorter.sort(x)
} }
// Strings sorts x using the rules of c. // SortStrings uses sort.Sort to sort the strings in x using the rules of c.
func (c *Collator) Strings(x []string) { func (c *Collator) SortStrings(x []string) {
c.sorter.init(len(x)) c.sorter.init(len(x))
for i, s := range x { for i, s := range x {
c.sorter.keys[i] = c.KeyFromString(c.sorter.buf, s) c.sorter.keys[i] = c.KeyFromString(c.sorter.buf, s)
......
...@@ -14,12 +14,13 @@ func ExampleCollator_Strings() { ...@@ -14,12 +14,13 @@ func ExampleCollator_Strings() {
c := collate.New("root") c := collate.New("root")
strings := []string{ strings := []string{
"ad", "ad",
"ab",
"äb", "äb",
"ac", "ac",
} }
c.Strings(strings) c.SortStrings(strings)
fmt.Println(strings) fmt.Println(strings)
// Output: [äb ac ad] // Output: [ab äb ac ad]
} }
type sorter []string type sorter []string
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment