Skip to content

Commit d738c07

Browse files
authored
Merge pull request #198 from Thorium/master
Faster type comparisons
2 parents 4348d6a + b88bca3 commit d738c07

2 files changed

Lines changed: 4 additions & 4 deletions

File tree

src/FSharp.SystemTextJson/Collection.fs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -197,7 +197,7 @@ type JsonMapConverter(fsOptions: JsonFSharpOptions) =
197197
| MapFormat.Object -> jsonMapObjectConverter genArgs options
198198
| MapFormat.ArrayOfPairs -> jsonMapArrayOfPairsConverter genArgs
199199
| MapFormat.ObjectOrArrayOfPairs ->
200-
if genArgs[0] = typeof<string> || isWrappedString genArgs[0] then
200+
if Type.(=)(genArgs[0], typeof<string>) || isWrappedString genArgs[0] then
201201
jsonMapObjectConverter genArgs options
202202
else
203203
jsonMapArrayOfPairsConverter genArgs

src/FSharp.SystemTextJson/Helpers.fs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ let isClass ty =
9292
let rec tryGetNullValue (fsOptions: JsonFSharpOptionsRecord) (ty: Type) : obj voption =
9393
if isNullableUnion ty then
9494
ValueSome null
95-
elif ty = typeof<unit> then
95+
elif Type.(=)(ty, typeof<unit>) then
9696
ValueSome()
9797
elif fsOptions.UnionEncoding.HasFlag JsonUnionEncoding.UnwrapOption
9898
&& isValueOptionType ty then
@@ -149,7 +149,7 @@ let isWrappedString (ty: Type) =
149149

150150
cases.Length = 1
151151
&& let fields = cases[ 0 ].GetFields() in
152-
fields.Length = 1 && fields[0].PropertyType = typeof<string>
152+
fields.Length = 1 && Type.(=)(fields[0].PropertyType, typeof<string>)
153153

154154
type FieldHelper
155155
(
@@ -256,7 +256,7 @@ let getJsonFieldNames (getAttributes: Type -> obj[]) =
256256
|> readOnlyDict
257257

258258
let getConverterForDictionaryKey<'T> (options: JsonSerializerOptions) =
259-
if typeof<'T> = typeof<string> then
259+
if Type.(=)(typeof<'T>, typeof<string>) then
260260
// Pre-8.0, the built-in StringConverter doesn't support {Read|Write}AsPropertyName() correctly.
261261
// See https://github.com/dotnet/runtime/issues/77326
262262
{ new JsonConverter<string>() with

0 commit comments

Comments
 (0)