Skip to content

Commit 91b12ec

Browse files
committed
cue: reuse adt.OpContext in Value.structValOpts
It called getStruct, which built an entirely new adt.OpContext rather than reusing the one the parent already had. The method was used only once too, so inline it to simplify. │ old │ new │ │ sec/op │ sec/op vs base │ LargeValueMarshalJSON-8 6.370m ± 1% 6.083m ± 1% -4.50% (p=0.002 n=6) │ old │ new │ │ B/op │ B/op vs base │ LargeValueMarshalJSON-8 4.178Mi ± 0% 3.445Mi ± 0% -17.56% (p=0.002 n=6) │ old │ new │ │ allocs/op │ allocs/op vs base │ LargeValueMarshalJSON-8 60.26k ± 0% 58.26k ± 0% -3.33% (p=0.002 n=6) Updates #2470. Signed-off-by: Daniel Martí <[email protected]> Change-Id: I28bd8b820bf022e48257b445aa2e6d6e628dfe16 Reviewed-on: https://review.gerrithub.io/c/cue-lang/cue/+/1201826 Reviewed-by: Roger Peppe <[email protected]> Reviewed-by: Marcel van Lohuizen <[email protected]> TryBot-Result: CUEcueckoo <[email protected]> Unity-Result: CUE porcuepine <[email protected]>
1 parent 0078d26 commit 91b12ec

File tree

1 file changed

+1
-12
lines changed

1 file changed

+1
-12
lines changed

cue/types.go

+1-12
Original file line numberDiff line numberDiff line change
@@ -1424,8 +1424,7 @@ func (v Value) structValOpts(ctx *adt.OpContext, o options) (s structValue, err
14241424
// Allow scalar values if hidden or definition fields are requested.
14251425
case !o.omitHidden, !o.omitDefinitions:
14261426
default:
1427-
obj, err = v.getStruct()
1428-
if err != nil {
1427+
if err := v.checkKind(ctx, adt.StructKind); err != nil && !err.ChildError {
14291428
return structValue{}, err
14301429
}
14311430
}
@@ -1487,16 +1486,6 @@ func (v hiddenValue) Struct() (*Struct, error) {
14871486
return &Struct{obj}, nil
14881487
}
14891488

1490-
func (v Value) getStruct() (*adt.Vertex, *adt.Bottom) {
1491-
ctx := v.ctx()
1492-
if err := v.checkKind(ctx, adt.StructKind); err != nil {
1493-
if !err.ChildError {
1494-
return nil, err
1495-
}
1496-
}
1497-
return v.v, nil
1498-
}
1499-
15001489
// Struct represents a CUE struct value.
15011490
type Struct struct {
15021491
structValue

0 commit comments

Comments
 (0)