Remove reader.TrySkip workaround in JsonDocument parse helper (#35484)
authorLayomi Akinrinade <laakinri@microsoft.com>
Mon, 27 Apr 2020 06:08:25 +0000 (02:08 -0400)
committerGitHub <noreply@github.com>
Mon, 27 Apr 2020 06:08:25 +0000 (23:08 -0700)
src/libraries/System.Text.Json/src/System/Text/Json/Document/JsonDocument.Parse.cs

index 2c305e0..0ffe89e 100644 (file)
@@ -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;