Use Directory.EnumerateFiles instead of Directory.GetFiles in WhichUtil.#2882
Use Directory.EnumerateFiles instead of Directory.GetFiles in WhichUtil.#2882TingluoHuang merged 3 commits intomainfrom
Directory.EnumerateFiles instead of Directory.GetFiles in WhichUtil.#2882Conversation
| #elif OS_WINDOWS | ||
| public static readonly OSPlatform Platform = OSPlatform.Windows; | ||
| #else | ||
| public static readonly OSPlatform Platform = OSPlatform.Linux; |
There was a problem hiding this comment.
add a #else to provide default value, so VSCode won't barking on us.
| #elif ARM64 | ||
| public static readonly Architecture PlatformArchitecture = Architecture.Arm64; | ||
| #else | ||
| public static readonly Architecture PlatformArchitecture = Architecture.X64; |
There was a problem hiding this comment.
same, help vscode a little bit...
There was a problem hiding this comment.
This makes sense and I'm happy to +1 it.
Rather than defaulting to X64 in this case, is it possible to, like, raise an error of some kind if we can't determine the system architecture? As a future developer, I'd rather see a compile-time error than have the preprocessor silently assume I'm on X64 when I'm not.
(I'm far from a C# preprocessor expert, so I'll defer to your judgment here and +1 whatever you think is best.)
| [Fact] | ||
| [Trait("Level", "L0")] | ||
| [Trait("Category", "Common")] | ||
| public void UseWhich2FindGit() |
There was a problem hiding this comment.
these tests are copy paste all existing tests but change Which() to Which2()
| { | ||
| try | ||
| { | ||
| foreach (var file in Directory.EnumerateFiles(pathSegment, command)) |
There was a problem hiding this comment.
GetFiles changed to EnumerateFiles
| searchPattern = StringUtil.Format($"{command}.*"); | ||
| try | ||
| { | ||
| foreach (var file in Directory.EnumerateFiles(pathSegment, searchPattern)) |
There was a problem hiding this comment.
GetFiles changed to EnumerateFiles
| #else | ||
| try | ||
| { | ||
| foreach (var file in Directory.EnumerateFiles(pathSegment, command)) |
There was a problem hiding this comment.
GetFiles changed to EnumerateFiles
pje
left a comment
There was a problem hiding this comment.
Left a minor comment. Overall +1! To me—someone who's only just literate in C#—it makes sense.
1bd3712 to
34d206a
Compare
Directory.GetFileswill return only after all search finish.Directory.EnumerateFileswill return file as they been found, so we can process them immediately.We introduce
Which2()in addition toWhich(), and the usage ofWhich2()is controlled by feature flag.After we verify the new
Which2()is functional properly, we can switch all the code path to useWhich2()https://github.com/github/c2c-actions-support/issues/2902