@@ -15,16 +15,28 @@ let illegalPathChars =
1515 let chars = Path.GetInvalidPathChars ()
1616 chars
1717
18- let checkPathForIllegalChars ( path : string ) =
19- let len = path.Length
20- for i = 0 to len - 1 do
21- let c = path.[ i]
18+ type private PathState =
19+ | Legal
20+ | Illegal of path : string * illegalChar : char
21+
22+ let private checkPathForIllegalChars =
23+ let cache = System.Collections.Concurrent.ConcurrentDictionary< string, PathState>()
24+ fun ( path : string ) ->
25+ match cache.TryGetValue path with
26+ | true , Legal -> ()
27+ | true , Illegal ( path, c) -> raise( IllegalFileNameChar( path, c))
28+ | _ ->
29+ let len = path.Length
30+ for i = 0 to len - 1 do
31+ let c = path.[ i]
2232
23- // Determine if this character is disallowed within a path by
24- // attempting to find it in the array of illegal path characters.
25- for badChar in illegalPathChars do
26- if c = badChar then
27- raise( IllegalFileNameChar( path, c))
33+ // Determine if this character is disallowed within a path by
34+ // attempting to find it in the array of illegal path characters.
35+ for badChar in illegalPathChars do
36+ if c = badChar then
37+ cache.[ path] <- Illegal( path, c)
38+ raise( IllegalFileNameChar( path, c))
39+ cache.[ path] <- Legal
2840
2941// Case sensitive (original behaviour preserved).
3042let checkSuffix ( x : string ) ( y : string ) = x.EndsWith( y, System.StringComparison.Ordinal)
0 commit comments