Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit1d5962e

Browse files
rojeppKevinRansom
authored andcommitted
Speed up checkPathForIllegalChars without a cache. (dotnet#2138)
Timing for 100k checks of the path "c:\dev\myproject\utilities\longstring with spaces\filename.fs":Original ~250msThis method ~100ms
1 parent74a1d42 commit1d5962e

File tree

1 file changed

+5
-18
lines changed

1 file changed

+5
-18
lines changed

‎src/utils/filename.fs‎

Lines changed: 5 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -7,24 +7,11 @@ open Microsoft.FSharp.Compiler.AbstractIL.Internal.Library
77

88
exception IllegalFileNameCharofstring*char
99

10-
/// The set of characters which may not be used in a path.
11-
/// This is saved here because Path.GetInvalidPathChars() allocates and returns
12-
/// a new array each time it's called (by necessity, for security reasons).
13-
/// This is only used within `checkPathForIllegalChars`, and is only read from.
14-
letillegalPathChars=
15-
letchars= Path.GetInvalidPathChars()
16-
chars
17-
18-
letcheckPathForIllegalChars(path:string)=
19-
letlen= path.Length
20-
for i=0to len-1do
21-
letc= path.[i]
22-
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 badCharin illegalPathCharsdo
26-
if c= badCharthen
27-
raise(IllegalFileNameChar(path, c))
10+
letcheckPathForIllegalChars=
11+
letchars=new System.Collections.Generic.HashSet<_>(Path.GetInvalidPathChars())
12+
(fun(path:string)->
13+
for cin pathdo
14+
if chars.Contains cthen raise(IllegalFileNameChar(path, c)))
2815

2916
// Case sensitive (original behaviour preserved).
3017
letcheckSuffix(x:string)(y:string)= x.EndsWith(y,System.StringComparison.Ordinal)

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp