Skip to content

Commit ca15d83

Browse files
committed
fix
1 parent deea917 commit ca15d83

1 file changed

Lines changed: 18 additions & 14 deletions

File tree

benchmarks/PolylineAlgorithm.Benchmarks/PolylineValidationBenchmark.cs

Lines changed: 18 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ public void Setup() {
3535
[Benchmark]
3636
public void Vectorized_Structure_Validation_3() => ValidateStructureVectorized(polyline);
3737

38-
public static void ValidateVectorized(ReadOnlySpan<char> polyline) {
38+
public static void ValidateCharsVectorized(ReadOnlySpan<char> polyline) {
3939
int length = polyline.Length;
4040
int vectorSize = Vector<ushort>.Count;
4141

@@ -73,19 +73,8 @@ public static void ValidateVectorized(ReadOnlySpan<char> polyline) {
7373
}
7474
}
7575

76-
/// <summary>
77-
/// Validates that a polyline is structurally correct:
78-
/// - All characters are in the allowed range
79-
/// - No block exceeds 7 characters
80-
/// - Polyline ends with a block terminator
81-
/// </summary>
82-
/// <param name="polyline">The polyline to validate.</param>
83-
/// <exception cref="ArgumentException">Thrown if the polyline is structurally invalid.</exception>
84-
public static void ValidateStructureForeach(ReadOnlySpan<char> polyline) {
85-
// 1. SIMD character check (reuse existing method)
86-
ValidateVectorized(polyline);
8776

88-
// 2. Block structure check
77+
private static void ValidateBlockLength(ReadOnlySpan<char> polyline) {
8978
int blockLen = 0;
9079
bool foundBlockEnd = false;
9180

@@ -106,6 +95,21 @@ public static void ValidateStructureForeach(ReadOnlySpan<char> polyline) {
10695
throw new ArgumentException("Polyline does not end with a valid block terminator.", nameof(polyline));
10796
}
10897

98+
/// <summary>
99+
/// Validates that a polyline is structurally correct:
100+
/// - All characters are in the allowed range
101+
/// - No block exceeds 7 characters
102+
/// - Polyline ends with a block terminator
103+
/// </summary>
104+
/// <param name="polyline">The polyline to validate.</param>
105+
/// <exception cref="ArgumentException">Thrown if the polyline is structurally invalid.</exception>
106+
public static void ValidateStructureForeach(ReadOnlySpan<char> polyline) {
107+
// 1. SIMD character check (reuse existing method)
108+
ValidateCharsVectorized(polyline);
109+
// 2. Block structure check
110+
ValidateBlockLength(polyline);
111+
}
112+
109113
public static void ValidateStructureVectorized(ReadOnlySpan<char> polyline) {
110114
int length = polyline.Length;
111115
int vectorSize = Vector<ushort>.Count;
@@ -133,7 +137,7 @@ public static void ValidateStructureVectorized(ReadOnlySpan<char> polyline) {
133137
}
134138

135139
for (int j = 0; j < vectorSize; j++) {
136-
if (slice[j] != 0) {
140+
if (slice[j] < End) {
137141
int globalIndex = i + j;
138142
if (globalIndex - blockEndIndex > 7) {
139143
throw new ArgumentException($"Block at position {blockEndIndex + 1} exceeds 7 characters.", nameof(polyline));

0 commit comments

Comments
 (0)