1
1
// Licensed to the .NET Foundation under one or more agreements.
2
2
// The .NET Foundation licenses this file to you under the MIT license.
3
3
4
+ using System ;
5
+ using System . Buffers ;
4
6
using System . IO ;
5
7
using System . Linq ;
6
8
using Microsoft . Extensions . Primitives ;
@@ -9,23 +11,31 @@ namespace Microsoft.Extensions.FileProviders.Physical.Internal
9
11
{
10
12
internal static class PathUtils
11
13
{
12
- private static readonly char [ ] _invalidFileNameChars = Path . GetInvalidFileNameChars ( )
14
+ private static char [ ] GetInvalidFileNameChars ( ) => Path . GetInvalidFileNameChars ( )
13
15
. Where ( c => c != Path . DirectorySeparatorChar && c != Path . AltDirectorySeparatorChar ) . ToArray ( ) ;
14
16
15
- private static readonly char [ ] _invalidFilterChars = _invalidFileNameChars
17
+ private static char [ ] GetInvalidFilterChars ( ) => GetInvalidFileNameChars ( )
16
18
. Where ( c => c != '*' && c != '|' && c != '?' ) . ToArray ( ) ;
17
19
20
+ #if NET8_0_OR_GREATER
21
+ private static readonly IndexOfAnyValues < char > _invalidFileNameChars = IndexOfAnyValues . Create ( GetInvalidFileNameChars ( ) ) ;
22
+ private static readonly IndexOfAnyValues < char > _invalidFilterChars = IndexOfAnyValues . Create ( GetInvalidFilterChars ( ) ) ;
23
+ #else
24
+ private static readonly char [ ] _invalidFileNameChars = GetInvalidFileNameChars ( ) ;
25
+ private static readonly char [ ] _invalidFilterChars = GetInvalidFilterChars ( ) ;
26
+ #endif
27
+
18
28
private static readonly char [ ] _pathSeparators = new [ ]
19
29
{ Path . DirectorySeparatorChar , Path . AltDirectorySeparatorChar } ;
20
30
21
31
internal static bool HasInvalidPathChars ( string path )
22
32
{
23
- return path . IndexOfAny ( _invalidFileNameChars ) != - 1 ;
33
+ return path . AsSpan ( ) . IndexOfAny ( _invalidFileNameChars ) >= 0 ;
24
34
}
25
35
26
36
internal static bool HasInvalidFilterChars ( string path )
27
37
{
28
- return path . IndexOfAny ( _invalidFilterChars ) != - 1 ;
38
+ return path . AsSpan ( ) . IndexOfAny ( _invalidFilterChars ) >= 0 ;
29
39
}
30
40
31
41
internal static string EnsureTrailingSlash ( string path )
0 commit comments