this repo has no description
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

all: minor wins with strings.Cut and utf8.AppendRune

Both of these APIs were added in Go 1.18.
Note that utf8.AppendRune already has a fast path for ASCII.

Signed-off-by: Daniel Martí <mvdan@mvdan.cc>
Change-Id: Icab92b3f194e8395eaafaeb3a35398e3258ced11
Reviewed-on: https://review.gerrithub.io/c/cue-lang/cue/+/557324
TryBot-Result: CUEcueckoo <cueckoo@cuelang.org>
Reviewed-by: Paul Jolly <paul@myitcv.io>
Unity-Result: CUE porcuepine <cue.porcuepine@gmail.com>

+6 -15
+1 -1
cmd/cue/cmd/common.go
··· 77 77 if loc == "" { 78 78 loc = os.Getenv("LANG") 79 79 } 80 - loc = strings.Split(loc, ".")[0] 80 + loc, _, _ = strings.Cut(loc, ".") 81 81 return language.Make(loc) 82 82 } 83 83
+1 -3
cue/literal/quote.go
··· 223 223 } 224 224 225 225 func (f *Form) appendEscapedRune(buf []byte, r rune) []byte { 226 - var runeTmp [utf8.UTFMax]byte 227 226 if (!f.multiline && r == rune(f.quote)) || r == '\\' { // always backslashed 228 227 buf = f.appendEscape(buf) 229 228 buf = append(buf, byte(r)) ··· 235 234 return buf 236 235 } 237 236 } else if strconv.IsPrint(r) || f.graphicOnly && isInGraphicList(r) { 238 - n := utf8.EncodeRune(runeTmp[:], r) 239 - buf = append(buf, runeTmp[:n]...) 237 + buf = utf8.AppendRune(buf, r) 240 238 return buf 241 239 } 242 240 buf = f.appendEscape(buf)
+2 -4
cue/literal/string.go
··· 154 154 } 155 155 } 156 156 157 - var runeTmp [utf8.UTFMax]byte 158 157 buf := make([]byte, 0, 3*len(s)/2) // Try to avoid more allocations. 159 158 stripNL := false 160 159 wasEscapedNewline := false ··· 220 219 } 221 220 stripNL = false 222 221 wasEscapedNewline = false 223 - if c < utf8.RuneSelf || !multibyte { 222 + if !multibyte { 224 223 buf = append(buf, byte(c)) 225 224 } else { 226 - n := utf8.EncodeRune(runeTmp[:], c) 227 - buf = append(buf, runeTmp[:n]...) 225 + buf = utf8.AppendRune(buf, c) 228 226 } 229 227 } 230 228 // allow unmatched quotes if already checked.
+1 -2
internal/value/value.go
··· 51 51 52 52 // UnifyBuiltin returns the given Value unified with the given builtin template. 53 53 func UnifyBuiltin(v cue.Value, kind string) cue.Value { 54 - p := strings.Split(kind, ".") 55 - pkg, name := p[0], p[1] 54 + pkg, name, _ := strings.Cut(kind, ".") 56 55 s := runtime.SharedRuntime.LoadImport(pkg) 57 56 if s == nil { 58 57 return v
+1 -5
pkg/tool/os/env.go
··· 98 98 update := map[string]interface{}{} 99 99 100 100 for _, kv := range os.Environ() { 101 - a := strings.SplitN(kv, "=", 2) 102 - 103 - name := a[0] 104 - str := a[1] 105 - 101 + name, str, _ := strings.Cut(kv, "=") 106 102 if v := ctx.Obj.Lookup(name); v.Exists() { 107 103 update[name], err = fromString(name, str, v) 108 104 if err != nil {