this repo has no description
0
fork

Configure Feed

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

cue: make use of Go 1.20+ APIs

Now that we require Go 1.20 or later, we can use reflect.Value.SetZero
and bytes.Clone, which are clearer and faster.

Signed-off-by: Daniel Martí <mvdan@mvdan.cc>
Change-Id: I6bee04ec9e42aaaa4d15e1bc8e1aa90d64b4134b
Reviewed-on: https://review.gerrithub.io/c/cue-lang/cue/+/1167629
TryBot-Result: CUEcueckoo <cueckoo@cuelang.org>
Unity-Result: CUE porcuepine <cue.porcuepine@gmail.com>
Reviewed-by: Roger Peppe <rogpeppe@gmail.com>

+4 -5
+3 -4
cue/decode.go
··· 70 70 71 71 func (d *decoder) clear(x reflect.Value) { 72 72 if x.CanSet() { 73 - x.Set(reflect.Zero(x.Type())) 73 + x.SetZero() 74 74 } 75 75 } 76 76 ··· 373 373 } 374 374 } 375 375 376 - elemType := t.Elem() 377 376 if !mapElem.IsValid() { 378 - mapElem = reflect.New(elemType).Elem() 377 + mapElem = reflect.New(t.Elem()).Elem() 379 378 } else { 380 - mapElem.Set(reflect.Zero(elemType)) 379 + mapElem.SetZero() 381 380 } 382 381 d.decode(mapElem, iter.Value(), false) 383 382
+1 -1
cue/types.go
··· 1332 1332 ctx := v.ctx() 1333 1333 switch x := v.eval(ctx).(type) { 1334 1334 case *adt.Bytes: 1335 - return append([]byte(nil), x.B...), nil 1335 + return bytes.Clone(x.B), nil 1336 1336 case *adt.String: 1337 1337 return []byte(x.Str), nil 1338 1338 }