]> Cypherpunks repositories - gostls13.git/commitdiff
sort: rename helpers: s/Sort// in sort.Sort[Float64s|Ints|Strings]
authorAndrew Gerrand <adg@golang.org>
Fri, 8 Jul 2011 00:52:50 +0000 (10:52 +1000)
committerAndrew Gerrand <adg@golang.org>
Fri, 8 Jul 2011 00:52:50 +0000 (10:52 +1000)
Includes 'sorthelpers' gofix and updates to tree.

R=golang-dev, gri
CC=golang-dev
https://golang.org/cl/4631098

19 files changed:
src/cmd/godoc/codewalk.go
src/cmd/godoc/index.go
src/cmd/godoc/mapping.go
src/cmd/godoc/utils.go
src/cmd/gofix/Makefile
src/cmd/gofix/sorthelpers.go [new file with mode: 0644]
src/cmd/gofix/sorthelpers_test.go [new file with mode: 0644]
src/cmd/hgpatch/main.go
src/pkg/exp/template/exec_test.go
src/pkg/go/doc/doc.go
src/pkg/http/header.go
src/pkg/index/suffixarray/suffixarray.go
src/pkg/index/suffixarray/suffixarray_test.go
src/pkg/net/hosts_test.go
src/pkg/path/filepath/match.go
src/pkg/sort/sort.go
src/pkg/sort/sort_test.go
src/pkg/time/sleep_test.go
src/pkg/unicode/maketables.go

index 74178cecd0e08af9d0df016523d8ff9f14bee374..50043e2abaf01b03ae1f3689b764b86d3ba888d8 100644 (file)
@@ -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
 }
index 91bd905d8ef0a75613f43c71c7e8acd9d8093aee..e0c89e7949da69c37320258fffb03b775216048c 100644 (file)
@@ -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 {
index 83f34810cc072f3bda78d00c773b77dc154af64c..92614e83e88d439c67ad204e9f75896d9fbdfc5f 100644 (file)
@@ -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 {
index 660bf6d0438cecdb2c65e3df3212c72787869cc6..e2637ab3d5733aa6e1b252d246c14461fcd91d9c 100644 (file)
@@ -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 {
index e74b639df4fa423ae79788077b3ebf48926bb140..7ce21e8aab5163350e06e2bacf86acd14d53db3a 100644 (file)
@@ -19,6 +19,7 @@ GOFILES=\
        procattr.go\
        reflect.go\
        signal.go\
+       sorthelpers.go\
        sortslice.go\
        stringssplit.go\
        typecheck.go\
diff --git a/src/cmd/gofix/sorthelpers.go b/src/cmd/gofix/sorthelpers.go
new file mode 100644 (file)
index 0000000..4d0bee6
--- /dev/null
@@ -0,0 +1,47 @@
+// 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
+}
diff --git a/src/cmd/gofix/sorthelpers_test.go b/src/cmd/gofix/sorthelpers_test.go
new file mode 100644 (file)
index 0000000..6c37858
--- /dev/null
@@ -0,0 +1,45 @@
+// 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)
+}
+`,
+       },
+}
index 6a197bd54b5e08aa75421b7a78189023ed8be26c..4f7aec22b2ea94d077d54bddcada646a7de66286 100644 (file)
@@ -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)
        }
index 8992299ebf018e8c5ee296810502c26551934167..86b958e840f04a454abee411dd329102aeb54260 100644 (file)
@@ -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
 }
 
index a7a7e0a32587cc6e0060af661df2a773710f6d8f..b26cd2bed5b95c3b602a88a7affe7e37be97ec70 100644 (file)
@@ -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
index 95a25a814bde11435337512bfb4e2097c9c2f4ab..08b07713041e5fb71417dd8414534d194e9266fd 100644 (file)
@@ -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)
index 079b7d8ed0bcfef8d1bec107147c72d1d4afc605..9d4e93217b878fa39b5ebd50f4fdc9a4747ea607 100644 (file)
@@ -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 {
index b1499027ad5848471b53c75e8fed850cf5a91031..385ff0e56a64edd222048915c37cbe0c98682c3e 100644 (file)
@@ -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))
index e5793eef2c72c1245d96907f80fed9daa3d49c88..1bd00541c6df7038bf9a323d282524471651bbca 100644 (file)
@@ -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)
index 9c344309d2a6b8061d9ab1857c26edcd2563cb1a..7fcc214c05839c6836f186271d8b53babc0c59fa 100644 (file)
@@ -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)
index b707579590e55abf327400d177a769d08a4fd04d..daed61ea8d1f80c29f8b9853e44816f10487d66b 100644 (file)
@@ -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.
index 29359c83fb87b4692f7566dacaa5c69ab9efc544..4da262637707303a9fd844051f26ba1bbb7b34c8 100644 (file)
@@ -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
index 25e79f9fbc440f2712e68b217aaa96644d654f7a..a4a1a429fde1c4a34c6f0313c8cf7d3ab9103c93 100644 (file)
@@ -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 {
index 97fa8e3040ed07e586a2fcddb5666c5805c38c32..07b931d7ee72857d9ac3eb9586388f3568463922 100644 (file)
@@ -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