mirror of
https://github.com/kovidgoyal/kitty.git
synced 2026-08-04 06:36:24 +00:00
Bump go version to 1.21
Allows us to use the much faster builtin min/max functions for two variable min/max
This commit is contained in:
parent
f125ffe3e0
commit
49ea26968c
17 changed files with 44 additions and 53 deletions
|
|
@ -3,6 +3,7 @@
|
|||
package utils
|
||||
|
||||
import (
|
||||
"cmp"
|
||||
"fmt"
|
||||
"os"
|
||||
"path/filepath"
|
||||
|
|
@ -98,19 +99,13 @@ func sort_with_key[T any, C constraints.Ordered](stable bool, s []T, key func(a
|
|||
for i, x := range s {
|
||||
temp[i].val, temp[i].key = x, key(x)
|
||||
}
|
||||
cmp := func(a, b t) int {
|
||||
if a.key < b.key {
|
||||
return -1
|
||||
}
|
||||
if a.key > b.key {
|
||||
return 1
|
||||
}
|
||||
return 0
|
||||
key_cmp := func(a, b t) int {
|
||||
return cmp.Compare(a.key, b.key)
|
||||
}
|
||||
if stable {
|
||||
slices.SortStableFunc(temp, cmp)
|
||||
slices.SortStableFunc(temp, key_cmp)
|
||||
} else {
|
||||
slices.SortFunc(temp, cmp)
|
||||
slices.SortFunc(temp, key_cmp)
|
||||
}
|
||||
for i, x := range temp {
|
||||
s[i] = x.val
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue