From: Layomi Akinrinade Date: Mon, 27 Apr 2020 06:08:25 +0000 (-0400) Subject: Remove reader.TrySkip workaround in JsonDocument parse helper (#35484) X-Git-Tag: submit/tizen/20210909.063632~8354 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=17d6691ad32331d1ebc2e25e394d5f36c17fb18b;p=platform%2Fupstream%2Fdotnet%2Fruntime.git Remove reader.TrySkip workaround in JsonDocument parse helper (#35484) --- diff --git a/src/libraries/System.Text.Json/src/System/Text/Json/Document/JsonDocument.Parse.cs b/src/libraries/System.Text.Json/src/System/Text/Json/Document/JsonDocument.Parse.cs index 2c305e0..0ffe89e 100644 --- a/src/libraries/System.Text.Json/src/System/Text/Json/Document/JsonDocument.Parse.cs +++ b/src/libraries/System.Text.Json/src/System/Text/Json/Document/JsonDocument.Parse.cs @@ -380,31 +380,18 @@ namespace System.Text.Json { long startingOffset = reader.TokenStartIndex; - // Placeholder until reader.Skip() is written (https://github.com/dotnet/runtime/issues/27838) + if (!reader.TrySkip()) { - int depth = reader.CurrentDepth; - - // CurrentDepth rises late and falls fast, - // a payload of "[ 1, 2, 3, 4 ]" will report post-Read() - // CurrentDepth values of { 0, 1, 1, 1, 1, 0 }, - // Since we're logically at 0 ([), Read() once and keep - // reading until we've come back down to 0 (]). - do + if (shouldThrow) { - if (!reader.Read()) - { - if (shouldThrow) - { - ThrowHelper.ThrowJsonReaderException( - ref reader, - ExceptionResource.ExpectedJsonTokens); - } - - reader = restore; - document = null; - return false; - } - } while (reader.CurrentDepth > depth); + ThrowHelper.ThrowJsonReaderException( + ref reader, + ExceptionResource.ExpectedJsonTokens); + } + + reader = restore; + document = null; + return false; } long totalLength = reader.BytesConsumed - startingOffset;