{
while (count > 0)
{
- ReplaceInPlaceAtChunk(ref chunk, ref indexInChunk, valuePtr, value.Length);
+ ReplaceInPlaceAtChunk(ref chunk!, ref indexInChunk, valuePtr, value.Length);
--count;
}
if (span.Length != Length)
return false;
- StringBuilder sbChunk = this;
+ StringBuilder? sbChunk = this;
int offset = 0;
do
if (!chunk.EqualsOrdinal(span.Slice(span.Length - offset, chunk_length)))
return false;
- Debug.Assert(sbChunk.m_ChunkPrevious != null);
sbChunk = sbChunk.m_ChunkPrevious;
} while (sbChunk != null);
int indexInChunk = startIndex - chunk.m_ChunkOffset;
while (count > 0)
{
- Debug.Assert(chunk != null);
+ Debug.Assert(chunk != null, "chunk was null in replace");
// Look for a match in the chunk,indexInChunk pointer
if (StartsWith(chunk, indexInChunk, count, oldValue))
{
int indexBeforeAdjustment = index;
// See if we accumulated any replacements, if so apply them.
- Debug.Assert(replacements != null);
+ Debug.Assert(replacements != null || replacementsCount == 0, "replacements was null and replacementsCount != 0");
ReplaceAllInChunk(replacements, replacementsCount, chunk, oldValue.Length, newValue);
// The replacement has affected the logical index. Adjust it.
index += ((newValue.Length - oldValue.Length) * replacementsCount);
StringBuilder chunk;
int indexInChunk;
MakeRoom(index, valueCount, out chunk, out indexInChunk, false);
- ReplaceInPlaceAtChunk(ref chunk, ref indexInChunk, value, valueCount);
+ ReplaceInPlaceAtChunk(ref chunk!, ref indexInChunk, value, valueCount);
}
}
/// <remarks>
/// This routine is very efficient because it does replacements in bulk.
/// </remarks>
- private void ReplaceAllInChunk(int[] replacements, int replacementsCount, StringBuilder sourceChunk, int removeCount, string value)
+ private void ReplaceAllInChunk(int[]? replacements, int replacementsCount, StringBuilder sourceChunk, int removeCount, string value)
{
if (replacementsCount <= 0)
{
{
fixed (char* valuePtr = value)
{
+ Debug.Assert(replacements != null, "replacements was null when replacementsCount > 0");
// calculate the total amount of extra space or space needed for all the replacements.
long longDelta = (value.Length - removeCount) * (long)replacementsCount;
int delta = (int)longDelta;
for (;;)
{
// Copy in the new string for the ith replacement
- ReplaceInPlaceAtChunk(ref targetChunk, ref targetIndexInChunk, valuePtr, value.Length);
+ ReplaceInPlaceAtChunk(ref targetChunk!, ref targetIndexInChunk, valuePtr, value.Length);
int gapStart = replacements[i] + removeCount;
i++;
if (i >= replacementsCount)
{
// Copy the gap data between the current replacement and the next replacement
fixed (char* sourcePtr = &sourceChunk.m_ChunkChars[gapStart])
- ReplaceInPlaceAtChunk(ref targetChunk, ref targetIndexInChunk, sourcePtr, gapEnd - gapStart);
+ ReplaceInPlaceAtChunk(ref targetChunk!, ref targetIndexInChunk, sourcePtr, gapEnd - gapStart);
}
else
{
/// </param>
/// <param name="value">The pointer to the start of the character buffer.</param>
/// <param name="count">The number of characters in the buffer.</param>
- private unsafe void ReplaceInPlaceAtChunk(ref StringBuilder chunk, ref int indexInChunk, char* value, int count)
+ private unsafe void ReplaceInPlaceAtChunk(ref StringBuilder? chunk, ref int indexInChunk, char* value, int count)
{
if (count != 0)
{
for (;;)
{
+ Debug.Assert(chunk != null, "chunk should not be null at this point");
int lengthInChunk = chunk.m_ChunkLength - indexInChunk;
Debug.Assert(lengthInChunk >= 0, "Index isn't in the chunk.");
indexInChunk += lengthToCopy;
if (indexInChunk >= chunk.m_ChunkLength)
{
- StringBuilder? nextChunk = Next(chunk);
- Debug.Assert(nextChunk != null, "we should never get past last chunk because range should already be validated before calling");
- chunk = nextChunk;
+ chunk = Next(chunk);
indexInChunk = 0;
}
count -= lengthToCopy;