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:
Kovid Goyal
2023-08-09 11:58:16 +05:30
parent f125ffe3e0
commit 49ea26968c
17 changed files with 44 additions and 53 deletions

View File

@@ -216,7 +216,7 @@ func check_resize(frame *ImageFrame, filename string) error {
}
func (frame *ImageFrame) set_delay(min_gap, delay int) {
frame.Delay_ms = int32(utils.Max(min_gap, delay) * 10)
frame.Delay_ms = int32(max(min_gap, delay) * 10)
if frame.Delay_ms == 0 {
frame.Delay_ms = -1 // gapless frame in the graphics protocol
}
@@ -308,7 +308,7 @@ func parse_identify_record(ans *IdentifyRecord, raw *IdentifyOutput) (err error)
if err != nil {
return fmt.Errorf("Invalid gap value in identify output: %s", raw.Gap)
}
ans.Gap = utils.Max(0, ans.Gap)
ans.Gap = max(0, ans.Gap)
}
area, pos, found := strings.Cut(raw.Canvas, "+")
ok := false

View File

@@ -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

View File

@@ -507,7 +507,7 @@ func (self *wrapper) wrap_text(text string) []string {
}
func new_wrapper(opts WrapOptions, width int) *wrapper {
width = utils.Max(2, width)
width = max(2, width)
ans := wrapper{indent: opts.Indent, width: width, trim_whitespace: opts.Trim_whitespace, indent_width: wcswidth.Stringwidth(opts.Indent)}
if opts.Ignore_lines_containing != "" {
ans.ignore_lines_containing = utils.Splitlines(opts.Ignore_lines_containing)