Skip to content
This repository was archived by the owner on Jan 23, 2023. It is now read-only.

Commit 92b9b1e

Browse files
committed
Move RuntimePropertyCache to JsonClassInfo
1 parent 5d363fa commit 92b9b1e

File tree

3 files changed

+12
-10
lines changed

3 files changed

+12
-10
lines changed

src/System.Text.Json/src/System/Text/Json/Serialization/JsonClassInfo.AddProperty.cs

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -212,24 +212,25 @@ internal JsonPropertyInfo CreateRootObject(JsonSerializerOptions options)
212212

213213
internal JsonPropertyInfo GetOrAddPolymorphicProperty(JsonPropertyInfo property, Type runtimePropertyType, JsonSerializerOptions options)
214214
{
215-
static JsonPropertyInfo CreateRuntimeProperty(Type runtimePropertyType, (JsonPropertyInfo property, JsonSerializerOptions options, Type classType) arg)
215+
static JsonPropertyInfo CreateRuntimeProperty((JsonPropertyInfo property, Type runtimePropertyType) key, (JsonSerializerOptions options, Type classType) arg)
216216
{
217217
JsonPropertyInfo runtimeProperty = CreateProperty(
218-
arg.property.DeclaredPropertyType, runtimePropertyType,
219-
arg.property.ImplementedPropertyType,
220-
arg.property.PropertyInfo,
218+
key.property.DeclaredPropertyType, key.runtimePropertyType,
219+
key.property.ImplementedPropertyType,
220+
key.property.PropertyInfo,
221221
parentClassType: arg.classType,
222222
converter: null,
223223
options: arg.options);
224224

225-
arg.property.CopyRuntimeSettingsTo(runtimeProperty);
225+
key.property.CopyRuntimeSettingsTo(runtimeProperty);
226226

227227
return runtimeProperty;
228228
}
229229

230-
var cache = LazyInitializer.EnsureInitialized(ref property.RuntimePropertyCache, () => new ConcurrentDictionary<Type, JsonPropertyInfo>());
230+
ConcurrentDictionary<(JsonPropertyInfo, Type), JsonPropertyInfo> cache =
231+
LazyInitializer.EnsureInitialized(ref RuntimePropertyCache, () => new ConcurrentDictionary<(JsonPropertyInfo, Type), JsonPropertyInfo>());
231232

232-
return cache.GetOrAdd(runtimePropertyType, (type, arg) => CreateRuntimeProperty(type, arg), (property, options, Type));
233+
return cache.GetOrAdd((property, runtimePropertyType), (key, arg) => CreateRuntimeProperty(key, arg), (options, Type));
233234
}
234235
}
235236
}

src/System.Text.Json/src/System/Text/Json/Serialization/JsonClassInfo.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
// See the LICENSE file in the project root for more information.
44

55
using System.Collections;
6+
using System.Collections.Concurrent;
67
using System.Collections.Generic;
78
using System.Diagnostics;
89
using System.Reflection;
@@ -27,6 +28,9 @@ internal sealed partial class JsonClassInfo
2728
// All of the serializable properties on a POCO (except the optional extension property) keyed on property name.
2829
public volatile Dictionary<string, JsonPropertyInfo> PropertyCache;
2930

31+
// Serializable runtime/polymorphic proerties, keyed on property and runtime type.
32+
public ConcurrentDictionary<(JsonPropertyInfo, Type), JsonPropertyInfo> RuntimePropertyCache;
33+
3034
// All of the serializable properties on a POCO including the optional extension property.
3135
// Used for performance during serialization instead of 'PropertyCache' above.
3236
public volatile JsonPropertyInfo[] PropertyCacheArray;

src/System.Text.Json/src/System/Text/Json/Serialization/JsonPropertyInfo.cs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
// See the LICENSE file in the project root for more information.
44

55
using System.Collections;
6-
using System.Collections.Concurrent;
76
using System.Diagnostics;
87
using System.Reflection;
98
using System.Text.Json.Serialization;
@@ -585,7 +584,5 @@ private void VerifyWrite(int originalDepth, Utf8JsonWriter writer)
585584
ThrowHelper.ThrowJsonException_SerializationConverterWrite(ConverterBase);
586585
}
587586
}
588-
589-
public ConcurrentDictionary<Type, JsonPropertyInfo> RuntimePropertyCache;
590587
}
591588
}

0 commit comments

Comments
 (0)