Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Minor File.ReadAllBytes* improvements #61519
Minor File.ReadAllBytes* improvements #61519
Changes from all commits
eeb5e0b
87aaf3d
2b6b22b
39c2621
29b6b8d
9963347
9755a45
9fa8190
2576390
File filter
Filter by extension
Conversations
Jump to
There are no files selected for viewing
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: maybe turn this into a static property, like
PlatformSequentialScanOption
.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we instead just ensure we have tests that read files that return 0 for the length?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We have some tests, and you are the person who authored most of them: dotnet/corefx#28388
The problem is that they don't guarantee that all possible code paths are going to be executed (using stack-allocated array, renting an array from the pool, returning it and renting a larger array etc) as they deal with a virtual file system that seems to be exposing files only for reading.
We could use pipes (#58434 introduced some tests for that ), but it would require more work and handling all edge cases.
I know that setting
fileLength
to0
with#if DEBUG
is ugly, but it gives us what we need with a very little effort.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does it? It means, for example, that Debug.Asserts in the normal non-zero code paths are now rendered useless.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Which asserts do you mean? I can't see any in the code path for regular files that report length properly:
runtime/src/libraries/System.Private.CoreLib/src/System/IO/File.cs
Lines 548 to 567 in 2576390
runtime/src/libraries/System.Private.CoreLib/src/System/IO/File.cs
Lines 275 to 289 in 2576390
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Any on any code paths used from here all the way down through the runtime. The change says that the 99.9% code path is never executed in debug.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These paths (namely
RandomAccess.ReadAtOffsetAsync
andRandomAccess.ReadAtOffset
) have an excellent test code coverage (directly asRandomAccess
tests and indirectly viaFileStream
tests) so I am not worried about it.I do understand that it's not a clear win and a a trade off.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same question/comment as earlier.