@@ -173,15 +173,21 @@ import (
173173// JSON cannot represent cyclic data structures and Marshal does not
174174// handle them. Passing cyclic structures to Marshal will result in
175175// an error.
176- func Marshal (v any ) ([]byte , error ) {
176+ // EDIT(begin): add optimization options
177+ func Marshal (v any , opts ... Option ) ([]byte , error ) {
178+ // EDIT(end): add optimization options
177179 e := newEncodeState ()
178180 defer encodeStatePool .Put (e )
179181
180- // SHIM(begin): don't escape HTML by default
181- err := e .marshal (v , encOpts {escapeHTML : shims .EscapeHTMLByDefault })
182+ // EDIT(begin): don't escape HTML by default, and apply options
183+ encOpts := encOpts {escapeHTML : shims .EscapeHTMLByDefault }
184+ if opts != nil {
185+ encOpts = encOpts .apply (opts ... )
186+ }
187+ err := e .marshal (v , encOpts )
182188 // ORIGINAL:
183189 // err := e.marshal(v, encOpts{escapeHTML: true})
184- // SHIM (end)
190+ // EDIT (end)
185191 if err != nil {
186192 return nil , err
187193 }
@@ -352,6 +358,9 @@ type encOpts struct {
352358 // EDIT(begin): save the timefmt
353359 timefmt string
354360 // EDIT(end)
361+ // EDIT(begin): add optimization to skip compaction
362+ skipCompaction bool
363+ // EDIT(end)
355364}
356365
357366type encoderFunc func (e * encodeState , v reflect.Value , opts encOpts )
@@ -483,7 +492,7 @@ func marshalerEncoder(e *encodeState, v reflect.Value, opts encOpts) {
483492 if err == nil {
484493 e .Grow (len (b ))
485494 out := e .AvailableBuffer ()
486- out , err = appendCompact (out , b , opts . escapeHTML )
495+ out , err = appendCompact (out , b , opts )
487496 e .Buffer .Write (out )
488497 }
489498 if err != nil {
@@ -509,7 +518,7 @@ func addrMarshalerEncoder(e *encodeState, v reflect.Value, opts encOpts) {
509518 if err == nil {
510519 e .Grow (len (b ))
511520 out := e .AvailableBuffer ()
512- out , err = appendCompact (out , b , opts . escapeHTML )
521+ out , err = appendCompact (out , b , opts )
513522 e .Buffer .Write (out )
514523 }
515524 if err != nil {
0 commit comments