this repo has no description
0
fork

Configure Feed

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

internal/core/convert: avoid allocating when checking for omitempty

strings.Split must allocate the resulting slice,
so use strings.SplitSeq instead.

│ old │ new │
│ B/op │ B/op vs base │
VetInventory 3.500Gi ± ∞ ¹ 3.498Gi ± ∞ ¹ -0.04% (p=1.000 n=1)

│ old │ new │
│ allocs/op │ allocs/op vs base │
VetInventory 29.92M ± ∞ ¹ 29.85M ± ∞ ¹ -0.23% (p=1.000 n=1)

Signed-off-by: Daniel Martí <mvdan@mvdan.cc>
Change-Id: I1c93cdf83b2804db2ac0fc5f3de29ba8da26ddb3
Reviewed-on: https://review.gerrithub.io/c/cue-lang/cue/+/1234624
Reviewed-by: Marcel van Lohuizen <mpvl@gmail.com>
Unity-Result: CUE porcuepine <cue.porcuepine@gmail.com>
TryBot-Result: CUEcueckoo <cueckoo@cuelang.org>

+8 -4
+8 -4
internal/core/convert/go.go
··· 182 182 } 183 183 184 184 // isOmitEmpty means that the zero value is interpreted as undefined. 185 - func isOmitEmpty(f *reflect.StructField) bool { 185 + func isOmitEmpty(f reflect.StructField) bool { 186 186 isOmitEmpty := false 187 187 switch f.Type.Kind() { 188 188 case reflect.Pointer, reflect.Map, reflect.Chan, reflect.Interface, reflect.Slice: ··· 197 197 tag, ok := f.Tag.Lookup("json") 198 198 if ok { 199 199 isOmitEmpty = false 200 - if slices.Contains(strings.Split(tag, ",")[1:], "omitempty") { 201 - return true 200 + i := 0 201 + for s := range strings.SplitSeq(tag, ",") { 202 + if i > 0 && s == "omitempty" { 203 + return true 204 + } 205 + i++ 202 206 } 203 207 } 204 208 return isOmitEmpty ··· 384 388 if tag, _ := sf.Tag.Lookup("json"); tag == "-" { 385 389 continue 386 390 } 387 - if isOmitEmpty(&sf) && val.IsZero() { 391 + if isOmitEmpty(sf) && val.IsZero() { 388 392 continue 389 393 } 390 394 sub := fromGoValue(ctx, nilIsTop, val)