public void Push() { if (_continuationCount == 0) { Debug.Assert(Current.PolymorphicSerializationState != PolymorphicSerializationState.PolymorphicReEntrySuspended); if (_count == 0 && Current.PolymorphicSerializationState == PolymorphicSerializationState.None) { // Perf enhancement: do not create a new stackframe on the first push operation // unless the converter has primed the current frame for polymorphic dispatch. _count = 1; _indexOffset = 1; // currentIndex := _count - 1; } else { JsonTypeInfo jsonTypeInfo = Current.GetNestedJsonTypeInfo(); JsonNumberHandling?numberHandling = Current.NumberHandling; EnsurePushCapacity(); _stack[_count - _indexOffset] = Current; Current = default; _count++; Current.JsonTypeInfo = jsonTypeInfo; Current.JsonPropertyInfo = jsonTypeInfo.PropertyInfoForTypeInfo; // Allow number handling on property to win over handling on type. Current.NumberHandling = numberHandling ?? Current.JsonPropertyInfo.EffectiveNumberHandling; } } else { // We are re-entering a continuation, adjust indices accordingly if (_count++ > 0 || _indexOffset == 0) { Current = _stack[_count - _indexOffset]; } // check if we are done if (_continuationCount == _count) { _continuationCount = 0; } } #if DEBUG // Ensure the method is always exercised in debug builds. _ = PropertyPath(); #endif }
public void Push() { if (_continuationCount == 0) { if (_count == 0) { // Performance optimization: reuse the first stackframe on the first push operation. // NB need to be careful when making writes to Current _before_ the first `Push` // operation is performed. _count = 1; } else { JsonTypeInfo jsonTypeInfo = Current.GetNestedJsonTypeInfo(); JsonNumberHandling?numberHandling = Current.NumberHandling; EnsurePushCapacity(); _stack[_count - 1] = Current; Current = default; _count++; Current.JsonTypeInfo = jsonTypeInfo; Current.JsonPropertyInfo = jsonTypeInfo.PropertyInfoForTypeInfo; // Allow number handling on property to win over handling on type. Current.NumberHandling = numberHandling ?? Current.JsonPropertyInfo.NumberHandling; } } else { // We are re-entering a continuation, adjust indices accordingly if (_count++ > 0) { Current = _stack[_count - 1]; } // check if we are done if (_continuationCount == _count) { _continuationCount = 0; } } #if DEBUG // Ensure the method is always exercised in debug builds. _ = PropertyPath(); #endif }