aboutsummaryrefslogtreecommitdiff
path: root/src/sort
diff options
context:
space:
mode:
Diffstat (limited to 'src/sort')
-rw-r--r--src/sort/slice.go15
-rw-r--r--src/sort/slice_go113.go13
-rw-r--r--src/sort/slice_go14.go23
-rw-r--r--src/sort/slice_go18.go13
4 files changed, 9 insertions, 55 deletions
diff --git a/src/sort/slice.go b/src/sort/slice.go
index 443182b42e..d0b2102013 100644
--- a/src/sort/slice.go
+++ b/src/sort/slice.go
@@ -4,7 +4,10 @@
package sort
-import "math/bits"
+import (
+ "internal/reflectlite"
+ "math/bits"
+)
// Slice sorts the slice x given the provided less function.
// It panics if x is not a slice.
@@ -16,8 +19,8 @@ import "math/bits"
// The less function must satisfy the same requirements as
// the Interface type's Less method.
func Slice(x any, less func(i, j int) bool) {
- rv := reflectValueOf(x)
- swap := reflectSwapper(x)
+ rv := reflectlite.ValueOf(x)
+ swap := reflectlite.Swapper(x)
length := rv.Len()
limit := bits.Len(uint(length))
pdqsort_func(lessSwap{less, swap}, 0, length, limit)
@@ -30,15 +33,15 @@ func Slice(x any, less func(i, j int) bool) {
// The less function must satisfy the same requirements as
// the Interface type's Less method.
func SliceStable(x any, less func(i, j int) bool) {
- rv := reflectValueOf(x)
- swap := reflectSwapper(x)
+ rv := reflectlite.ValueOf(x)
+ swap := reflectlite.Swapper(x)
stable_func(lessSwap{less, swap}, rv.Len())
}
// SliceIsSorted reports whether the slice x is sorted according to the provided less function.
// It panics if x is not a slice.
func SliceIsSorted(x any, less func(i, j int) bool) bool {
- rv := reflectValueOf(x)
+ rv := reflectlite.ValueOf(x)
n := rv.Len()
for i := n - 1; i > 0; i-- {
if less(i, i-1) {
diff --git a/src/sort/slice_go113.go b/src/sort/slice_go113.go
deleted file mode 100644
index 53542dbd1a..0000000000
--- a/src/sort/slice_go113.go
+++ /dev/null
@@ -1,13 +0,0 @@
-// Copyright 2017 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.13
-// +build go1.13
-
-package sort
-
-import "internal/reflectlite"
-
-var reflectValueOf = reflectlite.ValueOf
-var reflectSwapper = reflectlite.Swapper
diff --git a/src/sort/slice_go14.go b/src/sort/slice_go14.go
deleted file mode 100644
index e477367618..0000000000
--- a/src/sort/slice_go14.go
+++ /dev/null
@@ -1,23 +0,0 @@
-// Copyright 2017 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.8
-// +build !go1.8
-
-package sort
-
-import "reflect"
-
-var reflectValueOf = reflect.ValueOf
-
-func reflectSwapper(x any) func(int, int) {
- v := reflectValueOf(x)
- tmp := reflect.New(v.Type().Elem()).Elem()
- return func(i, j int) {
- a, b := v.Index(i), v.Index(j)
- tmp.Set(a)
- a.Set(b)
- b.Set(tmp)
- }
-}
diff --git a/src/sort/slice_go18.go b/src/sort/slice_go18.go
deleted file mode 100644
index 1538477bc5..0000000000
--- a/src/sort/slice_go18.go
+++ /dev/null
@@ -1,13 +0,0 @@
-// Copyright 2017 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.8 && !go1.13
-// +build go1.8,!go1.13
-
-package sort
-
-import "reflect"
-
-var reflectValueOf = reflect.ValueOf
-var reflectSwapper = reflect.Swapper