Skip to content

Commit a12e8f8

Browse files
committed
simplify max length logic
1 parent 8c82de3 commit a12e8f8

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

src/Verify/Serialization/Scrubbers/DirectoryReplacements_StringBuilder.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -61,12 +61,12 @@ static List<Match> FindMatches(StringBuilder builder, List<Pair> pairs)
6161
var matchedRanges = new List<(int Start, int End)>();
6262
var absolutePosition = 0;
6363

64-
// Find the longest path to determine buffer sizes
65-
var maxPathLength = pairs.Max(_ => _.Find.Length);
66-
var carryoverSize = maxPathLength - 1;
64+
// pairs are ordered by length. so max length is the first one
65+
var maxLength = pairs[0].Find.Length;
66+
var carryoverSize = maxLength - 1;
6767

6868
Span<char> carryoverBuffer = stackalloc char[carryoverSize];
69-
Span<char> combinedBuffer = stackalloc char[maxPathLength * 2];
69+
Span<char> combinedBuffer = stackalloc char[maxLength * 2];
7070
var carryoverLength = 0;
7171
var previousChunkAbsoluteEnd = 0;
7272

0 commit comments

Comments
 (0)