Skip to content

Commit 5029d22

Browse files
committed
🎨 rename fastPath to isSimplePattern
Signed-off-by: Yves Bastide <[email protected]>
1 parent ab65c88 commit 5029d22

File tree

3 files changed

+12
-12
lines changed

3 files changed

+12
-12
lines changed

‎RobotsTxt/LongestMatchRobotsMatchStrategy.cs‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,11 +71,11 @@ internal static bool MatchesSlow(ReadOnlySpan<byte> path, ReadOnlySpan<byte> pat
7171
}
7272

7373
[MethodImpl(MethodImplOptions.AggressiveInlining)]
74-
internal static int MatchFast(ReadOnlySpan<byte> path, ReadOnlySpan<byte> pattern, bool fastPath)
74+
internal static int MatchFast(ReadOnlySpan<byte> path, ReadOnlySpan<byte> pattern, bool isSimplePattern)
7575
{
7676
if (pattern.Length == 0) return 0;
7777
if (path.Length == 0) return -1;
78-
if (fastPath)
78+
if (isSimplePattern)
7979
{
8080
return path.StartsWith(pattern) ? pattern.Length : -1;
8181
}

‎RobotsTxt/RobotsMachine.cs‎

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,16 +10,16 @@ private class State;
1010

1111
private class UserAgentState : State;
1212

13-
private class AllowState(ReadOnlyMemory<byte> pattern, bool fastPath) : State
13+
private class AllowState(ReadOnlyMemory<byte> pattern, bool isSimplePattern) : State
1414
{
1515
public ReadOnlyMemory<byte> Pattern { get; } = pattern;
16-
public bool FastPath { get; } = fastPath;
16+
public bool IsSimplePattern { get; } = isSimplePattern;
1717
}
1818

19-
private class DisallowState(ReadOnlyMemory<byte> pattern, bool fastPath) : State
19+
private class DisallowState(ReadOnlyMemory<byte> pattern, bool isSimplePattern) : State
2020
{
2121
public ReadOnlyMemory<byte> Pattern { get; } = pattern;
22-
public bool FastPath { get; } = fastPath;
22+
public bool IsSimplePattern { get; } = isSimplePattern;
2323
}
2424

2525
private readonly List<byte[]> _userAgents;
@@ -216,10 +216,10 @@ private static (int, int) AssessAccessRules(byte[] path, List<State> states)
216216
switch (state)
217217
{
218218
case AllowState allow:
219-
allowHierarchy = Check(path, allow.Pattern.Span, allow.FastPath, allowHierarchy);
219+
allowHierarchy = Check(path, allow.Pattern.Span, allow.IsSimplePattern, allowHierarchy);
220220
break;
221221
case DisallowState disallow:
222-
disallowHierarchy = Check(path, disallow.Pattern.Span, disallow.FastPath, disallowHierarchy);
222+
disallowHierarchy = Check(path, disallow.Pattern.Span, disallow.IsSimplePattern, disallowHierarchy);
223223
break;
224224
}
225225
}
@@ -229,9 +229,9 @@ private static (int, int) AssessAccessRules(byte[] path, List<State> states)
229229
private static readonly byte[] IndexHtmBytes = "/index.htm"u8.ToArray();
230230

231231
[MethodImpl(MethodImplOptions.AggressiveInlining)]
232-
private static int Check(byte[] path, ReadOnlySpan<byte> pattern, bool fastPath, int currentPriority)
232+
private static int Check(byte[] path, ReadOnlySpan<byte> pattern, bool isSimplePattern, int currentPriority)
233233
{
234-
var priority = LongestMatchRobotsMatchStrategy.MatchFast(path, pattern, fastPath);
234+
var priority = LongestMatchRobotsMatchStrategy.MatchFast(path, pattern, isSimplePattern);
235235
if (priority < 0) return currentPriority;
236236
if (currentPriority < priority)
237237
{

‎TestRobotsTxt/TestLongestMatchRobotsMatchStrategy.cs‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,10 @@ public void TestMatch(string path, string pattern, bool expected, int len)
3030
Encoding.UTF8.GetBytes(pattern)
3131
);
3232
Assert.Equal(expected, actual);
33-
var fastPath = !pattern.AsSpan().ContainsAny("*$");
33+
var isSimplePattern = !pattern.AsSpan().ContainsAny("*$");
3434
var actualLen =
3535
LongestMatchRobotsMatchStrategy.MatchFast(Encoding.UTF8.GetBytes(path),
36-
Encoding.UTF8.GetBytes(pattern), fastPath
36+
Encoding.UTF8.GetBytes(pattern), isSimplePattern
3737
);
3838
Assert.Equal(len, actualLen);
3939
Assert.Equal(expected, actualLen >= 0);

0 commit comments

Comments
 (0)