Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit6919fc2

Browse files
authored
Don't box every single value type dictionary key. (#46460)
During slow path deserialization fallback to storing dictionary keyas object only when Read returns false.
1 parent83313ab commit6919fc2

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

‎src/libraries/System.Text.Json/src/System/Text/Json/Serialization/Converters/Collection/DictionaryDefaultConverter.cs‎

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,7 @@ internal sealed override bool OnTryRead(
176176
}
177177

178178
// Determine the property.
179+
TKeykey;
179180
if(state.Current.PropertyState<StackFramePropertyState.Name)
180181
{
181182
if(reader.TokenType==JsonTokenType.EndObject)
@@ -197,7 +198,12 @@ internal sealed override bool OnTryRead(
197198
}
198199
}
199200

200-
state.Current.DictionaryKey=ReadDictionaryKey(refreader,refstate);
201+
key=ReadDictionaryKey(refreader,refstate);
202+
}
203+
else
204+
{
205+
// DictionaryKey is assigned before all return false cases, null value is unreachable
206+
key=(TKey)state.Current.DictionaryKey!;
201207
}
202208

203209
if(state.Current.PropertyState<StackFramePropertyState.ReadValue)
@@ -206,6 +212,7 @@ internal sealed override bool OnTryRead(
206212

207213
if(!SingleValueReadWithReadAhead(elementConverter.ClassType,refreader,refstate))
208214
{
215+
state.Current.DictionaryKey=key;
209216
value=default;
210217
returnfalse;
211218
}
@@ -217,11 +224,11 @@ internal sealed override bool OnTryRead(
217224
boolsuccess=elementConverter.TryRead(refreader,typeof(TValue),options,refstate,outTValue?element);
218225
if(!success)
219226
{
227+
state.Current.DictionaryKey=key;
220228
value=default;
221229
returnfalse;
222230
}
223231

224-
TKeykey=(TKey)state.Current.DictionaryKey!;
225232
Add(key,element!,options,refstate);
226233
state.Current.EndElement();
227234
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp