@@ -15,135 +15,6 @@ namespace Ramstack.Globbing.Traversal;
1515[ SuppressMessage ( "ReSharper" , "RedundantCast" ) ]
1616internal static class PathHelper
1717{
18- /// <summary>
19- /// Searches for a path separator within a span of characters.
20- /// </summary>
21- /// <param name="path">The span of characters representing the path.</param>
22- /// <param name="flags">The flags indicating the type of path separators to match.</param>
23- /// <returns>
24- /// The index of the path separator if found; otherwise, <c>-1</c>.
25- /// </returns>
26- public static int SearchPathSeparator ( scoped ReadOnlySpan < char > path , MatchFlags flags )
27- {
28- var count = ( nint ) ( uint ) path . Length ;
29- ref var p = ref MemoryMarshal . GetReference ( path ) ;
30- return SearchPathSeparator ( ref p , count , flags ) ;
31- }
32-
33- /// <summary>
34- /// Searches for a path separator within a range of characters.
35- /// </summary>
36- /// <param name="p">A reference to the first character of the range.</param>
37- /// <param name="count">The number of characters to search through.</param>
38- /// <param name="flags">The flags indicating the type of path separators to match.</param>
39- /// <returns>
40- /// The index of the path separator if found; otherwise, <c>-1</c>.
41- /// </returns>
42- public static int SearchPathSeparator ( scoped ref char p , nint count , MatchFlags flags )
43- {
44- var index = ( nint ) 0 ;
45-
46- if ( ! Sse41 . IsSupported || count < Vector128 < ushort > . Count )
47- {
48- for ( ; index < count ; index ++ )
49- if ( Unsafe . Add ( ref p , index ) == '/'
50- || ( Unsafe . Add ( ref p , index ) == '\\ ' && flags == MatchFlags . Windows ) )
51- return ( int ) index ;
52-
53- return - 1 ;
54- }
55-
56- if ( ! Avx2 . IsSupported || count < Vector256 < ushort > . Count )
57- {
58- var slash = Vector128 . Create ( ( ushort ) '/' ) ;
59- var backslash = Vector128 . Create ( ( ushort ) '\\ ' ) ;
60- var allowEscaping = CreateAllowEscaping128Bitmask ( flags ) ;
61-
62- var tail = count - Vector128 < ushort > . Count ;
63-
64- Vector128 < ushort > chunk ;
65- Vector128 < ushort > comparison ;
66-
67- do
68- {
69- chunk = LoadVector128 ( ref p , index ) ;
70- comparison = Sse2 . Or (
71- Sse2 . CompareEqual ( chunk , slash ) ,
72- Sse2 . AndNot (
73- allowEscaping ,
74- Sse2 . CompareEqual ( chunk , backslash ) ) ) ;
75-
76- if ( ! Sse41 . TestZ ( comparison , comparison ) )
77- {
78- var position = BitOperations . TrailingZeroCount ( Sse2 . MoveMask ( comparison . AsByte ( ) ) ) ;
79- return ( int ) index + ( position >>> 1 ) ;
80- }
81-
82- index += Vector128 < ushort > . Count ;
83- }
84- while ( index + Vector128 < ushort > . Count <= count ) ;
85-
86- chunk = LoadVector128 ( ref p , tail ) ;
87- comparison = Sse2 . Or (
88- Sse2 . CompareEqual ( chunk , slash ) ,
89- Sse2 . AndNot (
90- allowEscaping ,
91- Sse2 . CompareEqual ( chunk , backslash ) ) ) ;
92-
93- if ( ! Sse41 . TestZ ( comparison , comparison ) )
94- {
95- var position = BitOperations . TrailingZeroCount ( Sse2 . MoveMask ( comparison . AsByte ( ) ) ) ;
96- return ( int ) tail + ( position >>> 1 ) ;
97- }
98-
99- return - 1 ;
100- }
101- else
102- {
103- var slash = Vector256 . Create ( ( ushort ) '/' ) ;
104- var backslash = Vector256 . Create ( ( ushort ) '\\ ' ) ;
105- var allowEscaping = CreateAllowEscaping256Bitmask ( flags ) ;
106- var tail = count - Vector256 < ushort > . Count ;
107-
108- Vector256 < ushort > chunk ;
109- Vector256 < ushort > comparison ;
110-
111- do
112- {
113- chunk = LoadVector256 ( ref p , index ) ;
114- comparison = Avx2 . Or (
115- Avx2 . CompareEqual ( chunk , slash ) ,
116- Avx2 . AndNot (
117- allowEscaping ,
118- Avx2 . CompareEqual ( chunk , backslash ) ) ) ;
119-
120- if ( ! Avx . TestZ ( comparison , comparison ) )
121- {
122- var position = BitOperations . TrailingZeroCount ( Avx2 . MoveMask ( comparison . AsByte ( ) ) ) ;
123- return ( int ) index + ( position >>> 1 ) ;
124- }
125-
126- index += Vector256 < ushort > . Count ;
127- }
128- while ( index + Vector256 < ushort > . Count <= count ) ;
129-
130- chunk = LoadVector256 ( ref p , tail ) ;
131- comparison = Avx2 . Or (
132- Avx2 . CompareEqual ( chunk , slash ) ,
133- Avx2 . AndNot (
134- allowEscaping ,
135- Avx2 . CompareEqual ( chunk , backslash ) ) ) ;
136-
137- if ( ! Avx . TestZ ( comparison , comparison ) )
138- {
139- var position = BitOperations . TrailingZeroCount ( Avx2 . MoveMask ( comparison . AsByte ( ) ) ) ;
140- return ( int ) tail + ( position >>> 1 ) ;
141- }
142-
143- return - 1 ;
144- }
145- }
146-
14718 /// <summary>
14819 /// Determines whether the specified path matches any of the specified patterns.
14920 /// </summary>
0 commit comments