this repo has no description
0
fork

Configure Feed

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

internal/core/conver: make use of reflect.Value.IsZero

Its behavior on all the types where isOmitEmpty can return true
is exactly the same, because it's the same concept after all.

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

+1 -25
+1 -25
internal/core/convert/go.go
··· 192 192 return compileExpr(ctx, expr) 193 193 } 194 194 195 - func isZero(v reflect.Value) bool { 196 - x := v.Interface() 197 - if x == nil { 198 - return true 199 - } 200 - switch k := v.Kind(); k { 201 - case reflect.Struct, reflect.Array: 202 - // we never allow optional values for these types. 203 - return false 204 - 205 - case reflect.Chan, reflect.Func, reflect.Interface, reflect.Map, 206 - reflect.Slice: 207 - // Note that for maps we preserve the distinction between a nil map and 208 - // an empty map. 209 - return v.IsNil() 210 - 211 - case reflect.String: 212 - return v.Len() == 0 213 - 214 - default: 215 - return x == reflect.Zero(v.Type()).Interface() 216 - } 217 - } 218 - 219 195 func GoValueToExpr(ctx *adt.OpContext, nilIsTop bool, x interface{}) adt.Expr { 220 196 e := convertRec(ctx, nilIsTop, x) 221 197 if e == nil { ··· 438 414 if tag, _ := sf.Tag.Lookup("json"); tag == "-" { 439 415 continue 440 416 } 441 - if isOmitEmpty(&sf) && isZero(val) { 417 + if isOmitEmpty(&sf) && val.IsZero() { 442 418 continue 443 419 } 444 420 sub := convertRec(ctx, nilIsTop, val.Interface())