Skip to content

Commit

Permalink
cue: reuse adt.OpContext in Value.structValOpts
Browse files Browse the repository at this point in the history
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]>
  • Loading branch information
mvdan committed Sep 30, 2024
1 parent 0078d26 commit 91b12ec
Showing 1 changed file with 1 addition and 12 deletions.
13 changes: 1 addition & 12 deletions cue/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -1424,8 +1424,7 @@ func (v Value) structValOpts(ctx *adt.OpContext, o options) (s structValue, err
// Allow scalar values if hidden or definition fields are requested.
case !o.omitHidden, !o.omitDefinitions:
default:
obj, err = v.getStruct()
if err != nil {
if err := v.checkKind(ctx, adt.StructKind); err != nil && !err.ChildError {
return structValue{}, err
}
}
Expand Down Expand Up @@ -1487,16 +1486,6 @@ func (v hiddenValue) Struct() (*Struct, error) {
return &Struct{obj}, nil
}

func (v Value) getStruct() (*adt.Vertex, *adt.Bottom) {
ctx := v.ctx()
if err := v.checkKind(ctx, adt.StructKind); err != nil {
if !err.ChildError {
return nil, err
}
}
return v.v, nil
}

// Struct represents a CUE struct value.
type Struct struct {
structValue
Expand Down

0 comments on commit 91b12ec

Please sign in to comment.