From 014c623435e97e80adcd8ae7f6b8021e6087ddad Mon Sep 17 00:00:00 2001 From: Vance Morrison Date: Fri, 18 May 2018 08:18:48 -0700 Subject: [PATCH] Improve comments, review feedback. --- .../shared/System/Text/StringBuilder.cs | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/src/System.Private.CoreLib/shared/System/Text/StringBuilder.cs b/src/System.Private.CoreLib/shared/System/Text/StringBuilder.cs index be61e26..285593e 100644 --- a/src/System.Private.CoreLib/shared/System/Text/StringBuilder.cs +++ b/src/System.Private.CoreLib/shared/System/Text/StringBuilder.cs @@ -563,8 +563,19 @@ namespace System.Text /// as chunks (ReadOnlyMemory) of characters. An example use is: /// /// foreach (ReadOnlyMemory chunk in sb.EnumerateChunks()) - /// { /* operate on chars using 'chunk' */ } + /// foreach(char c in chunk.Span) + /// { /* operation on c } /// + /// Note that creating a ReadOnlySpan from a ReadOnlyMemory is expensive compared to the + /// fetching of the character, so create a local variable for the SPAN if you need to use + /// a for statement for example + /// + /// foreach (ReadOnlyMemory chunk in sb.EnumerateChunks()) + /// { + /// var span = chunk.Span; + /// for(int i = 0; i < span.Length; i++) + /// { /* operation on span[i] */ } + /// } /// public ChunkEnumerable EnumerateChunks() => new ChunkEnumerable(this); @@ -583,7 +594,7 @@ namespace System.Text #region private internal ChunkEnumerable(StringBuilder stringBuilder) { - Debug.Assert(stringBuilder != null); // Because it is only called with at 'this' pointer. + Debug.Assert(stringBuilder != null); // Because it is only called with a 'this' pointer. _stringBuilder = stringBuilder; } private StringBuilder _stringBuilder; // We insure this is never null. @@ -593,7 +604,7 @@ namespace System.Text /// /// ChunkEnumerator supports the IEnumerator pattern so foreach works (see EnumerateChunks) /// It needs to be public (so the compiler can use it when building a foreach statement) - /// but users typically don't use it explicitly (which is why it is a nested type). + /// but users typically don't use it explicitly (which is why it is a nested type). /// public struct ChunkEnumerator { @@ -614,6 +625,7 @@ namespace System.Text _currentChunk = next; return true; } + /// /// Implements the IEnumerator pattern. /// @@ -668,6 +680,7 @@ namespace System.Text _chunks = new StringBuilder[chunkCount]; while (0 <= --chunkCount) { + Debug.Assert(stringBuilder != null); _chunks[chunkCount] = stringBuilder; stringBuilder = stringBuilder.m_ChunkPrevious; } -- 2.7.4