Skip to content

Commit bb269f9

Browse files
committed
.
1 parent 6eec98f commit bb269f9

File tree

4 files changed

+14
-12
lines changed

4 files changed

+14
-12
lines changed

src/Verify/Serialization/Scrubbers/CrossChunkMatcher.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ public static void ReplaceAll<TContext>(
1717
CrossChunkHandler<TContext> onCrossChunk,
1818
WithinChunkHandler<TContext> onWithinChunk)
1919
{
20+
Span<char> buffer = stackalloc char[maxLength];
2021
Span<char> carryoverBuffer = stackalloc char[maxLength - 1];
2122
var carryoverLength = 0;
2223
var previousChunkAbsoluteEnd = 0;
@@ -38,6 +39,7 @@ public static void ReplaceAll<TContext>(
3839
onCrossChunk(
3940
builder,
4041
carryoverBuffer,
42+
buffer,
4143
carryoverIndex,
4244
remainingInCarryover,
4345
chunkSpan,
@@ -77,6 +79,7 @@ public static void ReplaceAll<TContext>(
7779
public delegate void CrossChunkHandler<TContext>(
7880
StringBuilder builder,
7981
Span<char> carryoverBuffer,
82+
Span<char> buffer,
8083
int carryoverIndex,
8184
int remainingInCarryover,
8285
CharSpan currentChunkSpan,

src/Verify/Serialization/Scrubbers/DateScrubber.cs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -219,15 +219,14 @@ static void ReplaceInner(StringBuilder builder, string format, Counter counter,
219219
static void OnCrossChunk(
220220
StringBuilder builder,
221221
Span<char> carryoverBuffer,
222+
Span<char> buffer,
222223
int carryoverIndex,
223224
int remainingInCarryover,
224225
CharSpan currentChunkSpan,
225226
int absoluteStartPosition,
226227
MatchContext context,
227228
Action<Match> addMatch)
228229
{
229-
Span<char> combinedBuffer = stackalloc char[context.MaxLength];
230-
231230
// Try lengths from longest to shortest (greedy matching)
232231
for (var length = context.MaxLength; length >= context.MinLength; length--)
233232
{
@@ -240,15 +239,16 @@ static void OnCrossChunk(
240239
}
241240

242241
// Combine carryover and current chunk
243-
carryoverBuffer.Slice(carryoverIndex, remainingInCarryover).CopyTo(combinedBuffer);
244-
currentChunkSpan[..neededFromCurrent].CopyTo(combinedBuffer[remainingInCarryover..]);
242+
carryoverBuffer.Slice(carryoverIndex, remainingInCarryover).CopyTo(buffer);
243+
currentChunkSpan[..neededFromCurrent].CopyTo(buffer[remainingInCarryover..]);
245244

246-
var slice = combinedBuffer[..length];
245+
var slice = buffer[..length];
247246

248247
if (context.TryConvert(slice, context.Format, context.Counter, context.Culture, out var convert))
249248
{
250249
addMatch(new(absoluteStartPosition, length, convert));
251-
return; // Found match at this position
250+
// Found match at this position
251+
return;
252252
}
253253
}
254254
}

src/Verify/Serialization/Scrubbers/DirectoryReplacements_StringBuilder.cs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -52,15 +52,14 @@ public static void Replace(StringBuilder builder, List<Pair> paths)
5252
static void OnCrossChunk(
5353
StringBuilder builder,
5454
Span<char> carryoverBuffer,
55+
Span<char> buffer,
5556
int carryoverIndex,
5657
int remainingInCarryover,
5758
CharSpan currentChunkSpan,
5859
int absoluteStartPosition,
5960
MatchContext context,
6061
Action<Match> addMatch)
6162
{
62-
Span<char> combinedBuffer = stackalloc char[context.MaxLength];
63-
6463
foreach (var pair in context.Pairs)
6564
{
6665
var neededFromCurrent = pair.Find.Length - remainingInCarryover;
@@ -78,12 +77,12 @@ static void OnCrossChunk(
7877
}
7978

8079
var combinedLength = remainingInCarryover + neededFromCurrent;
81-
carryoverBuffer.Slice(carryoverIndex, remainingInCarryover).CopyTo(combinedBuffer);
82-
currentChunkSpan[..neededFromCurrent].CopyTo(combinedBuffer[remainingInCarryover..]);
80+
carryoverBuffer.Slice(carryoverIndex, remainingInCarryover).CopyTo(buffer);
81+
currentChunkSpan[..neededFromCurrent].CopyTo(buffer[remainingInCarryover..]);
8382

8483
if (!TryMatchAtCrossChunk(
8584
builder,
86-
combinedBuffer[..combinedLength],
85+
buffer[..combinedLength],
8786
currentChunkSpan,
8887
absoluteStartPosition,
8988
neededFromCurrent,

src/Verify/Serialization/Scrubbers/GuidScrubber.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ public static void ReplaceGuids(StringBuilder builder, Counter counter)
2424
static void OnCrossChunk(
2525
StringBuilder builder,
2626
Span<char> carryoverBuffer,
27+
Span<char> buffer,
2728
int carryoverIndex,
2829
int remainingInCarryover,
2930
CharSpan currentChunkSpan,
@@ -54,7 +55,6 @@ static void OnCrossChunk(
5455
}
5556

5657
// Combine carryover and current chunk into buffer
57-
Span<char> buffer = stackalloc char[36];
5858
carryoverBuffer.Slice(carryoverIndex, remainingInCarryover).CopyTo(buffer);
5959
currentChunkSpan[..neededFromCurrent].CopyTo(buffer[remainingInCarryover..]);
6060

0 commit comments

Comments
 (0)