Skip to content

Commit 3f1e72b

Browse files
committed
cue: recursively marshal JSON values directly
cue.Value implements json.Marshaler, so any call of json.Marshal with a cue.Value is a roundabout way to just call cue.Value.MarshalJSON. Moreover, we can call the internal API directly, which gives us more flexibility such as reusing buffers later on. │ old │ new │ │ sec/op │ sec/op vs base │ LargeValueMarshalJSON-8 106.23m ± 1% 12.19m ± 1% -88.52% (p=0.002 n=6) │ old │ new │ │ B/op │ B/op vs base │ LargeValueMarshalJSON-8 48.24Mi ± 8% 23.51Mi ± 0% -51.27% (p=0.002 n=6) │ old │ new │ │ allocs/op │ allocs/op vs base │ LargeValueMarshalJSON-8 106.17k ± 2% 78.36k ± 0% -26.19% (p=0.002 n=6) Updates #2470. Signed-off-by: Daniel Martí <[email protected]> Change-Id: I1b0713489a5e888ab997389257772d2249d4389b Reviewed-on: https://review.gerrithub.io/c/cue-lang/cue/+/1201807 Unity-Result: CUE porcuepine <[email protected]> Reviewed-by: Roger Peppe <[email protected]> TryBot-Result: CUEcueckoo <[email protected]>
1 parent 01b0064 commit 3f1e72b

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

cue/types.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@ func (o *structValue) marshalJSON() (b []byte, err error) {
154154
}
155155
b = append(b, s...)
156156
b = append(b, ':')
157-
bb, err := internaljson.Marshal(v)
157+
bb, err := v.marshalJSON()
158158
if err != nil {
159159
return nil, err
160160
}
@@ -298,7 +298,7 @@ func marshalList(l *Iterator) (b []byte, err error) {
298298
b = append(b, '[')
299299
if l.Next() {
300300
for i := 0; ; i++ {
301-
x, err := internaljson.Marshal(l.Value())
301+
x, err := l.Value().marshalJSON()
302302
if err != nil {
303303
return nil, err
304304
}

0 commit comments

Comments
 (0)