Commit 5bcbcab3 authored by Andrew Gerrand's avatar Andrew Gerrand

sort: rename helpers: s/Sort// in sort.Sort[Float64s|Ints|Strings]

Includes 'sorthelpers' gofix and updates to tree.

R=golang-dev, gri
CC=golang-dev
https://golang.org/cl/4631098
parent e67a2504
......@@ -168,7 +168,7 @@ func loadCodewalk(filename string) (*Codewalk, os.Error) {
cw.File[i] = f
i++
}
sort.SortStrings(cw.File)
sort.Strings(cw.File)
return cw, nil
}
......
......@@ -954,7 +954,7 @@ func (list positionList) Swap(i, j int) { list[i], list[j] = list[j], list[
// unique returns the list sorted and with duplicate entries removed
func unique(list []int) []int {
sort.SortInts(list)
sort.Ints(list)
var last int
i := 0
for _, x := range list {
......
......@@ -120,7 +120,7 @@ func (m *Mapping) PrefixList() []string {
}
// sort the list and remove duplicate entries
sort.SortStrings(list)
sort.Strings(list)
i := 0
prev := ""
for _, path := range list {
......
......@@ -80,7 +80,7 @@ func canonicalizePaths(list []string, filter func(path string) bool) []string {
list = list[0:i]
// sort the list and remove duplicate entries
sort.SortStrings(list)
sort.Strings(list)
i = 0
prev := ""
for _, path := range list {
......
......@@ -19,6 +19,7 @@ GOFILES=\
procattr.go\
reflect.go\
signal.go\
sorthelpers.go\
sortslice.go\
stringssplit.go\
typecheck.go\
......
// Copyright 2011 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package main
import (
"go/ast"
)
func init() {
register(fix{
"sorthelpers",
sorthelpers,
`Adapt code from sort.Sort[Ints|Float64s|Strings] to sort.[Ints|Float64s|Strings].
`,
})
}
func sorthelpers(f *ast.File) (fixed bool) {
if !imports(f, "sort") {
return
}
walk(f, func(n interface{}) {
s, ok := n.(*ast.SelectorExpr)
if !ok || !isTopName(s.X, "sort") {
return
}
switch s.Sel.String() {
case "SortFloat64s":
s.Sel.Name = "Float64s"
case "SortInts":
s.Sel.Name = "Ints"
case "SortStrings":
s.Sel.Name = "Strings"
default:
return
}
fixed = true
})
return
}
// Copyright 2011 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package main
func init() {
addTestCases(sorthelpersTests)
}
var sorthelpersTests = []testCase{
{
Name: "sortslice.0",
In: `package main
import (
"sort"
)
func main() {
var s []string
sort.SortStrings(s)
var i []ints
sort.SortInts(i)
var f []float64
sort.SortFloat64s(f)
}
`,
Out: `package main
import (
"sort"
)
func main() {
var s []string
sort.Strings(s)
var i []ints
sort.Ints(i)
var f []float64
sort.Float64s(f)
}
`,
},
}
......@@ -176,7 +176,7 @@ func main() {
list[i] = f
i++
}
sort.SortStrings(list)
sort.Strings(list)
for _, f := range list {
fmt.Printf("%s\n", f)
}
......
......@@ -108,7 +108,7 @@ func (t *T) MSort(m map[string]int) []string {
keys[i] = k
i++
}
sort.SortStrings(keys)
sort.Strings(keys)
return keys
}
......
......@@ -551,7 +551,7 @@ func (doc *docReader) newDoc(importpath string, filenames []string) *PackageDoc
p := new(PackageDoc)
p.PackageName = doc.pkgName
p.ImportPath = importpath
sort.SortStrings(filenames)
sort.Strings(filenames)
p.Filenames = filenames
p.Doc = CommentText(doc.doc)
// makeTypeDocs may extend the list of doc.values and
......
......@@ -56,7 +56,7 @@ func (h Header) WriteSubset(w io.Writer, exclude map[string]bool) os.Error {
keys = append(keys, k)
}
}
sort.SortStrings(keys)
sort.Strings(keys)
for _, k := range keys {
for _, v := range h[k] {
v = strings.Replace(v, "\n", " ", -1)
......
......@@ -115,7 +115,7 @@ func (x *Index) FindAllIndex(r *regexp.Regexp, n int) (result [][]int) {
if len(indices) == 0 {
return
}
sort.SortInts(indices)
sort.Ints(indices)
pairs := make([]int, 2*len(indices))
result = make([][]int, len(indices))
count := 0
......@@ -159,7 +159,7 @@ func (x *Index) FindAllIndex(r *regexp.Regexp, n int) (result [][]int) {
if len(indices) == 0 {
return
}
sort.SortInts(indices)
sort.Ints(indices)
result = result[0:0]
prev := 0
for _, i := range indices {
......
......@@ -141,7 +141,7 @@ func testLookup(t *testing.T, tc *testCase, x *Index, s string, n int) {
// we cannot simply check that the res and exp lists are equal
// check that each result is in fact a correct match and there are no duplicates
sort.SortInts(res)
sort.Ints(res)
for i, r := range res {
if r < 0 || len(tc.source) <= r {
t.Errorf("test %q, lookup %q, result %d (n = %d): index %d out of range [0, %d[", tc.name, s, i, n, r, len(tc.source))
......
......@@ -59,7 +59,7 @@ func TestLookupHost(t *testing.T) {
// duplicate addresses (a common bug due to the way
// getaddrinfo works).
addrs, _ := LookupHost("localhost")
sort.SortStrings(addrs)
sort.Strings(addrs)
for i := 0; i+1 < len(addrs); i++ {
if addrs[i] == addrs[i+1] {
t.Fatalf("LookupHost(\"localhost\") = %v, has duplicate addresses", addrs)
......
......@@ -272,7 +272,7 @@ func glob(dir, pattern string, matches []string) (m []string, e os.Error) {
if err != nil {
return
}
sort.SortStrings(names)
sort.Strings(names)
for _, n := range names {
matched, err := Match(pattern, n)
......
......@@ -190,12 +190,12 @@ func (p StringSlice) Sort() { Sort(p) }
// Convenience wrappers for common cases
// SortInts sorts a slice of ints in increasing order.
func SortInts(a []int) { Sort(IntSlice(a)) }
// SortFloat64s sorts a slice of float64s in increasing order.
func SortFloat64s(a []float64) { Sort(Float64Slice(a)) }
// SortStrings sorts a slice of strings in increasing order.
func SortStrings(a []string) { Sort(StringSlice(a)) }
// Ints sorts a slice of ints in increasing order.
func Ints(a []int) { Sort(IntSlice(a)) }
// Float64s sorts a slice of float64s in increasing order.
func Float64s(a []float64) { Sort(Float64Slice(a)) }
// Strings sorts a slice of strings in increasing order.
func Strings(a []string) { Sort(StringSlice(a)) }
// IntsAreSorted tests whether a slice of ints is sorted in increasing order.
......
......@@ -46,27 +46,27 @@ func TestSortStringSlice(t *testing.T) {
}
}
func TestSortInts(t *testing.T) {
func TestInts(t *testing.T) {
data := ints
SortInts(data[0:])
Ints(data[0:])
if !IntsAreSorted(data[0:]) {
t.Errorf("sorted %v", ints)
t.Errorf(" got %v", data)
}
}
func TestSortFloat64s(t *testing.T) {
func TestFloat64s(t *testing.T) {
data := float64s
SortFloat64s(data[0:])
Float64s(data[0:])
if !Float64sAreSorted(data[0:]) {
t.Errorf("sorted %v", float64s)
t.Errorf(" got %v", data)
}
}
func TestSortStrings(t *testing.T) {
func TestStrings(t *testing.T) {
data := strings
SortStrings(data[0:])
Strings(data[0:])
if !StringsAreSorted(data[0:]) {
t.Errorf("sorted %v", strings)
t.Errorf(" got %v", data)
......@@ -85,7 +85,7 @@ func TestSortLarge_Random(t *testing.T) {
if IntsAreSorted(data) {
t.Fatalf("terrible rand.rand")
}
SortInts(data)
Ints(data)
if !IntsAreSorted(data) {
t.Errorf("sort didn't sort - 1M ints")
}
......@@ -99,7 +99,7 @@ func BenchmarkSortString1K(b *testing.B) {
data[i] = strconv.Itoa(i ^ 0x2cc)
}
b.StartTimer()
SortStrings(data)
Strings(data)
b.StopTimer()
}
}
......@@ -112,7 +112,7 @@ func BenchmarkSortInt1K(b *testing.B) {
data[i] = i ^ 0x2cc
}
b.StartTimer()
SortInts(data)
Ints(data)
b.StopTimer()
}
}
......@@ -125,7 +125,7 @@ func BenchmarkSortInt64K(b *testing.B) {
data[i] = i ^ 0xcccc
}
b.StartTimer()
SortInts(data)
Ints(data)
b.StopTimer()
}
}
......@@ -241,9 +241,9 @@ func TestBentleyMcIlroy(t *testing.T) {
for i := 0; i < n; i++ {
mdata[i] = data[i]
}
// SortInts is known to be correct
// Ints is known to be correct
// because mode Sort runs after mode _Copy.
SortInts(mdata)
Ints(mdata)
case _Dither:
for i := 0; i < n; i++ {
mdata[i] = data[i] + i%5
......
......@@ -172,7 +172,7 @@ func testAfterQueuing(t *testing.T) os.Error {
for _, slot := range slots {
go await(slot, result, After(int64(slot)*Delta))
}
sort.SortInts(slots)
sort.Ints(slots)
for _, slot := range slots {
r := <-result
if r.slot != slot {
......
......@@ -1042,7 +1042,7 @@ func printCasefold() {
if orb == nil {
continue
}
sort.SortInts(orb)
sort.Ints(orb)
c := orb[len(orb)-1]
for _, d := range orb {
chars[c].caseOrbit = d
......
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