@@ -127,7 +127,7 @@ func makeBoolArshaler(t reflect.Type) *arshaler {
127
127
}
128
128
129
129
// Optimize for marshaling without preceding whitespace.
130
- if optimizeCommon && ! xe .Flags .Get (jsonflags .AnyWhitespace ) && ! mo . Flags . Get ( jsonflags .StringifyBoolsAndStrings ) && ! xe .Tokens .Last .NeedObjectName () {
130
+ if optimizeCommon && ! mo .Flags .Get (jsonflags .AnyWhitespace | jsonflags .StringifyBoolsAndStrings ) && ! xe .Tokens .Last .NeedObjectName () {
131
131
xe .Buf = strconv .AppendBool (xe .Tokens .MayAppendDelim (xe .Buf , 't' ), va .Bool ())
132
132
xe .Tokens .Last .Increment ()
133
133
if xe .NeedFlush () {
@@ -200,7 +200,7 @@ func makeStringArshaler(t reflect.Type) *arshaler {
200
200
201
201
// Optimize for marshaling without preceding whitespace or string escaping.
202
202
s := va .String ()
203
- if optimizeCommon && ! xe .Flags .Get (jsonflags .AnyWhitespace ) && ! mo . Flags . Get ( jsonflags .StringifyBoolsAndStrings ) && ! xe .Tokens .Last .NeedObjectName () && ! jsonwire .NeedEscape (s ) {
203
+ if optimizeCommon && ! mo .Flags .Get (jsonflags .AnyWhitespace | jsonflags .StringifyBoolsAndStrings ) && ! xe .Tokens .Last .NeedObjectName () && ! jsonwire .NeedEscape (s ) {
204
204
b := xe .Buf
205
205
b = xe .Tokens .MayAppendDelim (b , '"' )
206
206
b = append (b , '"' )
@@ -446,7 +446,7 @@ func makeIntArshaler(t reflect.Type) *arshaler {
446
446
}
447
447
448
448
// Optimize for marshaling without preceding whitespace or string escaping.
449
- if optimizeCommon && ! xe .Flags .Get (jsonflags .AnyWhitespace ) && ! mo . Flags . Get ( jsonflags .StringifyNumbers ) && ! xe .Tokens .Last .NeedObjectName () {
449
+ if optimizeCommon && ! mo .Flags .Get (jsonflags .AnyWhitespace | jsonflags .StringifyNumbers ) && ! xe .Tokens .Last .NeedObjectName () {
450
450
xe .Buf = strconv .AppendInt (xe .Tokens .MayAppendDelim (xe .Buf , '0' ), va .Int (), 10 )
451
451
xe .Tokens .Last .Increment ()
452
452
if xe .NeedFlush () {
@@ -533,7 +533,7 @@ func makeUintArshaler(t reflect.Type) *arshaler {
533
533
}
534
534
535
535
// Optimize for marshaling without preceding whitespace or string escaping.
536
- if optimizeCommon && ! xe .Flags .Get (jsonflags .AnyWhitespace ) && ! mo . Flags . Get ( jsonflags .StringifyNumbers ) && ! xe .Tokens .Last .NeedObjectName () {
536
+ if optimizeCommon && ! mo .Flags .Get (jsonflags .AnyWhitespace | jsonflags .StringifyNumbers ) && ! xe .Tokens .Last .NeedObjectName () {
537
537
xe .Buf = strconv .AppendUint (xe .Tokens .MayAppendDelim (xe .Buf , '0' ), va .Uint (), 10 )
538
538
xe .Tokens .Last .Increment ()
539
539
if xe .NeedFlush () {
@@ -625,7 +625,7 @@ func makeFloatArshaler(t reflect.Type) *arshaler {
625
625
}
626
626
627
627
// Optimize for marshaling without preceding whitespace or string escaping.
628
- if optimizeCommon && ! xe .Flags .Get (jsonflags .AnyWhitespace ) && ! mo . Flags . Get ( jsonflags .StringifyNumbers ) && ! xe .Tokens .Last .NeedObjectName () {
628
+ if optimizeCommon && ! mo .Flags .Get (jsonflags .AnyWhitespace | jsonflags .StringifyNumbers ) && ! xe .Tokens .Last .NeedObjectName () {
629
629
xe .Buf = jsonwire .AppendFloat (xe .Tokens .MayAppendDelim (xe .Buf , '0' ), fv , bits )
630
630
xe .Tokens .Last .Increment ()
631
631
if xe .NeedFlush () {
@@ -755,7 +755,7 @@ func makeMapArshaler(t reflect.Type) *arshaler {
755
755
return enc .WriteToken (jsontext .Null )
756
756
}
757
757
// Optimize for marshaling an empty map without any preceding whitespace.
758
- if optimizeCommon && ! xe .Flags .Get (jsonflags .AnyWhitespace ) && ! xe .Tokens .Last .NeedObjectName () {
758
+ if optimizeCommon && ! mo .Flags .Get (jsonflags .AnyWhitespace ) && ! xe .Tokens .Last .NeedObjectName () {
759
759
xe .Buf = append (xe .Tokens .MayAppendDelim (xe .Buf , '{' ), "{}" ... )
760
760
xe .Tokens .Last .Increment ()
761
761
if xe .NeedFlush () {
@@ -785,7 +785,7 @@ func makeMapArshaler(t reflect.Type) *arshaler {
785
785
// A Go map guarantees that each entry has a unique key.
786
786
// As such, disable the expensive duplicate name check if we know
787
787
// that every Go key will serialize as a unique JSON string.
788
- if ! nonDefaultKey && mapKeyWithUniqueRepresentation (k .Kind (), xe .Flags .Get (jsonflags .AllowInvalidUTF8 )) {
788
+ if ! nonDefaultKey && mapKeyWithUniqueRepresentation (k .Kind (), mo .Flags .Get (jsonflags .AllowInvalidUTF8 )) {
789
789
xe .Tokens .Last .DisableNamespace ()
790
790
}
791
791
@@ -913,7 +913,7 @@ func makeMapArshaler(t reflect.Type) *arshaler {
913
913
// will be rejected as duplicates since they semantically refer
914
914
// to the same Go value. This is an unusual interaction
915
915
// between syntax and semantics, but is more correct.
916
- if ! nonDefaultKey && mapKeyWithUniqueRepresentation (k .Kind (), xd .Flags .Get (jsonflags .AllowInvalidUTF8 )) {
916
+ if ! nonDefaultKey && mapKeyWithUniqueRepresentation (k .Kind (), uo .Flags .Get (jsonflags .AllowInvalidUTF8 )) {
917
917
xd .Tokens .Last .DisableNamespace ()
918
918
}
919
919
@@ -922,7 +922,7 @@ func makeMapArshaler(t reflect.Type) *arshaler {
922
922
// since existing presence alone is insufficient to indicate
923
923
// whether the input had a duplicate name.
924
924
var seen reflect.Value
925
- if ! xd .Flags .Get (jsonflags .AllowDuplicateNames ) && va .Len () > 0 {
925
+ if ! uo .Flags .Get (jsonflags .AllowDuplicateNames ) && va .Len () > 0 {
926
926
seen = reflect .MakeMap (reflect .MapOf (k .Type (), emptyStructType ))
927
927
}
928
928
@@ -941,7 +941,7 @@ func makeMapArshaler(t reflect.Type) *arshaler {
941
941
}
942
942
943
943
if v2 := va .MapIndex (k .Value ); v2 .IsValid () {
944
- if ! xd .Flags .Get (jsonflags .AllowDuplicateNames ) && (! seen .IsValid () || seen .MapIndex (k .Value ).IsValid ()) {
944
+ if ! uo .Flags .Get (jsonflags .AllowDuplicateNames ) && (! seen .IsValid () || seen .MapIndex (k .Value ).IsValid ()) {
945
945
// TODO: Unread the object name.
946
946
name := xd .PreviousTokenOrValue ()
947
947
return newDuplicateNameError (dec .StackPointer (), nil , dec .InputOffset ()- len64 (name ))
@@ -1078,20 +1078,20 @@ func makeStructArshaler(t reflect.Type) *arshaler {
1078
1078
b := xe .Buf
1079
1079
if xe .Tokens .Last .Length () > 0 {
1080
1080
b = append (b , ',' )
1081
- if xe .Flags .Get (jsonflags .SpaceAfterComma ) {
1081
+ if mo .Flags .Get (jsonflags .SpaceAfterComma ) {
1082
1082
b = append (b , ' ' )
1083
1083
}
1084
1084
}
1085
- if xe .Flags .Get (jsonflags .Multiline ) {
1085
+ if mo .Flags .Get (jsonflags .Multiline ) {
1086
1086
b = xe .AppendIndent (b , xe .Tokens .NeedIndent ('"' ))
1087
1087
}
1088
1088
1089
1089
// Append the token to the output and to the state machine.
1090
1090
n0 := len (b ) // offset before calling AppendQuote
1091
- if ! xe .Flags .Get (jsonflags .EscapeForHTML | jsonflags .EscapeForJS | jsonflags .EscapeInvalidUTF8 ) {
1091
+ if ! mo .Flags .Get (jsonflags .EscapeForHTML | jsonflags .EscapeForJS | jsonflags .EscapeInvalidUTF8 ) {
1092
1092
b = append (b , f .quotedName ... )
1093
1093
} else {
1094
- b , _ = jsonwire .AppendQuote (b , f .name , & xe .Flags )
1094
+ b , _ = jsonwire .AppendQuote (b , f .name , & mo .Flags )
1095
1095
}
1096
1096
xe .Buf = b
1097
1097
xe .Names .ReplaceLastQuotedOffset (n0 )
@@ -1136,14 +1136,14 @@ func makeStructArshaler(t reflect.Type) *arshaler {
1136
1136
// Remember the previous written object member.
1137
1137
// The set of seen fields only needs to be updated to detect
1138
1138
// duplicate names with those from the inlined fallback.
1139
- if ! xe .Flags .Get (jsonflags .AllowDuplicateNames ) && fields .inlinedFallback != nil {
1139
+ if ! mo .Flags .Get (jsonflags .AllowDuplicateNames ) && fields .inlinedFallback != nil {
1140
1140
seenIdxs .insert (uint (f .id ))
1141
1141
}
1142
1142
prevIdx = f .id
1143
1143
}
1144
1144
if fields .inlinedFallback != nil && ! (mo .Flags .Get (jsonflags .DiscardUnknownMembers ) && fields .inlinedFallback .unknown ) {
1145
1145
var insertUnquotedName func ([]byte ) bool
1146
- if ! xe .Flags .Get (jsonflags .AllowDuplicateNames ) {
1146
+ if ! mo .Flags .Get (jsonflags .AllowDuplicateNames ) {
1147
1147
insertUnquotedName = func (name []byte ) bool {
1148
1148
// Check that the name from inlined fallback does not match
1149
1149
// one of the previously marshaled names from known fields.
@@ -1215,7 +1215,7 @@ func makeStructArshaler(t reflect.Type) *arshaler {
1215
1215
if uo .Flags .Get (jsonflags .RejectUnknownMembers ) && (fields .inlinedFallback == nil || fields .inlinedFallback .unknown ) {
1216
1216
return newUnmarshalErrorAfter (dec , t , ErrUnknownName )
1217
1217
}
1218
- if ! xd .Flags .Get (jsonflags .AllowDuplicateNames ) && ! xd .Namespaces .Last ().InsertUnquoted (name ) {
1218
+ if ! uo .Flags .Get (jsonflags .AllowDuplicateNames ) && ! xd .Namespaces .Last ().InsertUnquoted (name ) {
1219
1219
// TODO: Unread the object name.
1220
1220
return newDuplicateNameError (dec .StackPointer (), nil , dec .InputOffset ()- len64 (val ))
1221
1221
}
@@ -1234,7 +1234,7 @@ func makeStructArshaler(t reflect.Type) *arshaler {
1234
1234
continue
1235
1235
}
1236
1236
}
1237
- if ! xd .Flags .Get (jsonflags .AllowDuplicateNames ) && ! seenIdxs .insert (uint (f .id )) {
1237
+ if ! uo .Flags .Get (jsonflags .AllowDuplicateNames ) && ! seenIdxs .insert (uint (f .id )) {
1238
1238
// TODO: Unread the object name.
1239
1239
return newDuplicateNameError (dec .StackPointer (), nil , dec .InputOffset ()- len64 (val ))
1240
1240
}
@@ -1383,7 +1383,7 @@ func makeSliceArshaler(t reflect.Type) *arshaler {
1383
1383
return enc .WriteToken (jsontext .Null )
1384
1384
}
1385
1385
// Optimize for marshaling an empty slice without any preceding whitespace.
1386
- if optimizeCommon && ! xe .Flags .Get (jsonflags .AnyWhitespace ) && ! xe .Tokens .Last .NeedObjectName () {
1386
+ if optimizeCommon && ! mo .Flags .Get (jsonflags .AnyWhitespace ) && ! xe .Tokens .Last .NeedObjectName () {
1387
1387
xe .Buf = append (xe .Tokens .MayAppendDelim (xe .Buf , '[' ), "[]" ... )
1388
1388
xe .Tokens .Last .Increment ()
1389
1389
if xe .NeedFlush () {
@@ -1624,7 +1624,7 @@ func makePointerArshaler(t reflect.Type) *arshaler {
1624
1624
return err
1625
1625
}
1626
1626
if uo .Flags .Get (jsonflags .StringifyWithLegacySemantics ) &&
1627
- ( uo .Flags .Get (jsonflags .StringifyNumbers ) || uo . Flags . Get ( jsonflags .StringifyBoolsAndStrings ) ) {
1627
+ uo .Flags .Get (jsonflags .StringifyNumbers | jsonflags .StringifyBoolsAndStrings ) {
1628
1628
// A JSON null quoted within a JSON string should take effect
1629
1629
// within the pointer value, rather than the indirect value.
1630
1630
//
@@ -1664,7 +1664,7 @@ func makeInterfaceArshaler(t reflect.Type) *arshaler {
1664
1664
}
1665
1665
// Optimize for the any type if there are no special options.
1666
1666
if optimizeCommon &&
1667
- t == anyType && ! mo .Flags .Get (jsonflags .StringifyNumbers ) && ! mo . Flags . Get ( jsonflags .StringifyBoolsAndStrings ) && mo .Format == "" &&
1667
+ t == anyType && ! mo .Flags .Get (jsonflags .StringifyNumbers | jsonflags .StringifyBoolsAndStrings ) && mo .Format == "" &&
1668
1668
(mo .Marshalers == nil || ! mo .Marshalers .(* Marshalers ).fromAny ) {
1669
1669
return marshalValueAny (enc , va .Elem ().Interface (), mo )
1670
1670
}
@@ -1709,7 +1709,7 @@ func makeInterfaceArshaler(t reflect.Type) *arshaler {
1709
1709
// Duplicate name check must be enforced since unmarshalValueAny
1710
1710
// does not implement merge semantics.
1711
1711
if optimizeCommon &&
1712
- t == anyType && ! xd .Flags .Get (jsonflags .AllowDuplicateNames ) && uo .Format == "" &&
1712
+ t == anyType && ! uo .Flags .Get (jsonflags .AllowDuplicateNames ) && uo .Format == "" &&
1713
1713
(uo .Unmarshalers == nil || ! uo .Unmarshalers .(* Unmarshalers ).fromAny ) {
1714
1714
v , err := unmarshalValueAny (dec , uo )
1715
1715
// We must check for nil interface values up front.
0 commit comments