瀏覽代碼

speedup parsing multi-segment readOnlySequence

Jan Tattermusch 5 年之前
父節點
當前提交
b2d5ceb1f7
共有 1 個文件被更改,包括 5 次插入5 次删除
  1. 5 5
      csharp/src/Google.Protobuf/SegmentedBufferHelper.cs

+ 5 - 5
csharp/src/Google.Protobuf/SegmentedBufferHelper.cs

@@ -79,12 +79,12 @@ namespace Google.Protobuf
             }
             }
             else
             else
             {
             {
-                // TODO(jtattermusch): try to initialize the first segment, otherwise the
-                // very first read will result in slowpath (because the first thing to do is to
-                // refill to get the first buffer segment)
-                firstSpan = default;
-                instance.totalLength = (int) sequence.Length;
                 instance.readOnlySequenceEnumerator = sequence.GetEnumerator();
                 instance.readOnlySequenceEnumerator = sequence.GetEnumerator();
+                instance.totalLength = (int) sequence.Length;
+
+                // set firstSpan to the first segment
+                instance.readOnlySequenceEnumerator.MoveNext();
+                firstSpan = instance.readOnlySequenceEnumerator.Current.Span;
             }
             }
         }
         }