diff --git a/src/sort/sort.go b/src/sort/sort.go index 6db161f0c0..042ec4a8be 100644 --- a/src/sort/sort.go +++ b/src/sort/sort.go @@ -7,7 +7,10 @@ // Package sort provides primitives for sorting slices and user-defined collections. package sort -import "math/bits" +import ( + "math/bits" + "slices" +) // An implementation of Interface can be sorted by the routines in this package. // The methods refer to elements of the underlying collection by integer index. @@ -162,34 +165,34 @@ func (x StringSlice) Sort() { Sort(x) } // Ints sorts a slice of ints in increasing order. // // Note: as of Go 1.22, this function simply calls [slices.Sort]. -func Ints(x []int) { intsImpl(x) } +func Ints(x []int) { slices.Sort(x) } // Float64s sorts a slice of float64s in increasing order. // Not-a-number (NaN) values are ordered before other values. // // Note: as of Go 1.22, this function simply calls [slices.Sort]. -func Float64s(x []float64) { float64sImpl(x) } +func Float64s(x []float64) { slices.Sort(x) } // Strings sorts a slice of strings in increasing order. // // Note: as of Go 1.22, this function simply calls [slices.Sort]. -func Strings(x []string) { stringsImpl(x) } +func Strings(x []string) { slices.Sort(x) } // IntsAreSorted reports whether the slice x is sorted in increasing order. // // Note: as of Go 1.22, this function simply calls [slices.IsSorted]. -func IntsAreSorted(x []int) bool { return intsAreSortedImpl(x) } +func IntsAreSorted(x []int) bool { return slices.IsSorted(x) } // Float64sAreSorted reports whether the slice x is sorted in increasing order, // with not-a-number (NaN) values before any other values. // // Note: as of Go 1.22, this function simply calls [slices.IsSorted]. -func Float64sAreSorted(x []float64) bool { return float64sAreSortedImpl(x) } +func Float64sAreSorted(x []float64) bool { return slices.IsSorted(x) } // StringsAreSorted reports whether the slice x is sorted in increasing order. // // Note: as of Go 1.22, this function simply calls [slices.IsSorted]. -func StringsAreSorted(x []string) bool { return stringsAreSortedImpl(x) } +func StringsAreSorted(x []string) bool { return slices.IsSorted(x) } // Notes on stable sorting: // The used algorithms are simple and provable correct on all input and use diff --git a/src/sort/sort_impl_120.go b/src/sort/sort_impl_120.go deleted file mode 100644 index 5980da67e7..0000000000 --- a/src/sort/sort_impl_120.go +++ /dev/null @@ -1,15 +0,0 @@ -// Copyright 2023 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. - -//go:build !go1.21 - -package sort - -func intsImpl(x []int) { Sort(IntSlice(x)) } -func float64sImpl(x []float64) { Sort(Float64Slice(x)) } -func stringsImpl(x []string) { Sort(StringSlice(x)) } - -func intsAreSortedImpl(x []int) bool { return IsSorted(IntSlice(x)) } -func float64sAreSortedImpl(x []float64) bool { return IsSorted(Float64Slice(x)) } -func stringsAreSortedImpl(x []string) bool { return IsSorted(StringSlice(x)) } diff --git a/src/sort/sort_impl_go121.go b/src/sort/sort_impl_go121.go deleted file mode 100644 index 0a6a6a62e7..0000000000 --- a/src/sort/sort_impl_go121.go +++ /dev/null @@ -1,22 +0,0 @@ -// Copyright 2023 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. - -//go:build go1.21 - -// Starting with Go 1.21, we can leverage the new generic functions from the -// slices package to implement some `sort` functions faster. However, until -// the bootstrap compiler uses Go 1.21 or later, we keep a fallback version -// in sort_impl_120.go that retains the old implementation. - -package sort - -import "slices" - -func intsImpl(x []int) { slices.Sort(x) } -func float64sImpl(x []float64) { slices.Sort(x) } -func stringsImpl(x []string) { slices.Sort(x) } - -func intsAreSortedImpl(x []int) bool { return slices.IsSorted(x) } -func float64sAreSortedImpl(x []float64) bool { return slices.IsSorted(x) } -func stringsAreSortedImpl(x []string) bool { return slices.IsSorted(x) }