Skip to content

Commit

Permalink
rebase on go 1.21
Browse files Browse the repository at this point in the history
  • Loading branch information
PeterRK committed Jun 26, 2023
1 parent 1029a5e commit 0273040
Show file tree
Hide file tree
Showing 15 changed files with 2,397 additions and 339 deletions.
219 changes: 108 additions & 111 deletions README.md

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions bqs_disabled.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2022 The Go Authors. All rights reserved.
// 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.

Expand All @@ -7,9 +7,9 @@
package slices

import (
"golang.org/x/exp/constraints"
"cmp"
)

func tryBlockIntroSort[E constraints.Ordered](x []E) bool {
func tryBlockIntroSort[E cmp.Ordered](x []E) bool {
return false
}
20 changes: 6 additions & 14 deletions bqs_enabled.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2022 The Go Authors. All rights reserved.
// 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.

Expand All @@ -7,14 +7,13 @@
package slices

import (
"cmp"
"unsafe"

"golang.org/x/exp/constraints"
)

const bqsSize = 1024

func tryBlockIntroSort[E constraints.Ordered](list []E) bool {
func tryBlockIntroSort[E cmp.Ordered](list []E) bool {
var elem E
var word uintptr
if unsafe.Sizeof(elem) > unsafe.Sizeof(word) ||
Expand All @@ -27,7 +26,7 @@ func tryBlockIntroSort[E constraints.Ordered](list []E) bool {
return true
}

func blockIntroSort[E constraints.Ordered](list []E, chance int) {
func blockIntroSort[E cmp.Ordered](list []E, chance int) {
for len(list) >= bqsSize {
if chance--; chance < 0 {
heapSort(list)
Expand All @@ -43,22 +42,15 @@ func blockIntroSort[E constraints.Ordered](list []E, chance int) {
introSort(list, chance)
}

func min[E constraints.Ordered](a, b E) E {
if a < b {
return a
}
return b
}

func compGE[E constraints.Ordered](a, b E) int {
func compGE[E cmp.Ordered](a, b E) int {
if a < b {
return 0
} else {
return 1
}
}

func blockPartition[E constraints.Ordered](list []E) int {
func blockPartition[E cmp.Ordered](list []E) int {
size := len(list) // size >= 16

a, b, c := size/4, size/2, size*3/4
Expand Down
2 changes: 1 addition & 1 deletion cache_amd64.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2022 The Go Authors. All rights reserved.
// 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.

Expand Down
2 changes: 1 addition & 1 deletion cpuid_amd64.s
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2022 The Go Authors. All rights reserved.
// 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.

Expand Down
21 changes: 10 additions & 11 deletions genzfunc.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2022 The Go Authors. All rights reserved.
// 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.

Expand Down Expand Up @@ -35,8 +35,7 @@ func main() {
var newDecl []ast.Decl
for _, d := range af.Decls {
fd, ok := d.(*ast.FuncDecl)
if !ok || fd.Recv != nil ||
fd.Name.Name == "less" || fd.Name.IsExported() ||
if !ok || fd.Recv != nil || fd.Name.IsExported() ||
fd.Type.TypeParams == nil || len(fd.Type.TypeParams.List) != 1 {
continue
}
Expand All @@ -60,34 +59,34 @@ func main() {
tpl := out.Bytes()

funcPtn := regexp.MustCompile(`\nfunc `)
lessPtn := regexp.MustCompile(`less\([^\),]+,[^\),]+\)`)
lessPtn := regexp.MustCompile(`cmp\.Less\([^\),]+,[^\),]+\)`)

src := funcPtn.ReplaceAll(tpl, []byte("\nfunc (lt lessFunc[E]) "))
src = lessPtn.ReplaceAllFunc(src, func(origin []byte) []byte {
out := make([]byte, len(origin)-2)
out := make([]byte, len(origin)-6)
out[0] = 'l'
out[1] = 't'
for i := 2; i < len(out); i++ {
out[i] = origin[i+2]
out[i] = origin[i+6]
}
return out
})
dumpOrDie("zfunc_a.go", src)

src = funcPtn.ReplaceAll(tpl, []byte("\nfunc (lt refLessFunc[E]) "))
src = lessPtn.ReplaceAllFunc(src, func(origin []byte) []byte {
out := make([]byte, len(origin))
out := make([]byte, len(origin)-4)
out[0] = 'l'
out[1] = 't'
out[2] = '('
out[3] = '&'
pos := bytes.IndexByte(origin, ',')
pos := bytes.IndexByte(origin, ',') - 4
for i := 4; i < pos; i++ {
out[i] = origin[i+1]
out[i] = origin[i+5]
}
out[pos] = '&'
for i := pos + 1; i < len(out); i++ {
out[i] = origin[i]
out[i] = origin[i+4]
}
return out
})
Expand All @@ -111,7 +110,7 @@ func rewriteCalls(n ast.Node) ast.Visitor {

var header = `// Code generated from sort.go using genzfunc.go; DO NOT EDIT.
// Copyright 2022 The Go Authors. All rights reserved.
// 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.
Expand Down
4 changes: 1 addition & 3 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
module github.com/peterrk/slices

go 1.18

require golang.org/x/exp v0.0.0-20220428152302-39d4317da171
go 1.21
Loading

0 comments on commit 0273040

Please sign in to comment.