-
Notifications
You must be signed in to change notification settings - Fork 5.3k
Closed
Labels
area-System.IOgood first issueIssue should be easy to implement, good for first-time contributorsIssue should be easy to implement, good for first-time contributorshelp wanted[up-for-grabs] Good issue for external contributors[up-for-grabs] Good issue for external contributorstenet-performancePerformance related issuePerformance related issue
Milestone
Description
Today while trying to find an answer to #78390 I've realized that BufferedFileStreamStrategy has two different approaches to seeking.
Seek provides a smart way of seeking that tries to avoid losing the buffered data if possible:
runtime/src/libraries/System.Private.CoreLib/src/System/IO/Strategies/BufferedFileStreamStrategy.cs
Lines 936 to 946 in 031a16a
| // If the offset of the updated seek pointer in the buffer is still legal, then we can keep using the buffer: | |
| if (0 <= readPos && readPos < _readLen) | |
| { | |
| _readPos = (int)readPos; | |
| // Adjust the seek pointer of the underlying stream to reflect the amount of useful bytes in the read buffer: | |
| _strategy.Seek(_readLen - _readPos, SeekOrigin.Current); | |
| } | |
| else | |
| { // The offset of the updated seek pointer is not a legal offset. Loose the buffer. | |
| _readPos = _readLen = 0; | |
| } |
While Position setter is plain simple and always loses the buffered data:
runtime/src/libraries/System.Private.CoreLib/src/System/IO/Strategies/BufferedFileStreamStrategy.cs
Lines 66 to 77 in 031a16a
| set | |
| { | |
| if (_writePos > 0) | |
| { | |
| FlushWrite(); | |
| } | |
| _readPos = 0; | |
| _readLen = 0; | |
| _strategy.Position = value; | |
| } |
Position should be "smart" too and most likely just delegate the work to Seek
virzak
Metadata
Metadata
Assignees
Labels
area-System.IOgood first issueIssue should be easy to implement, good for first-time contributorsIssue should be easy to implement, good for first-time contributorshelp wanted[up-for-grabs] Good issue for external contributors[up-for-grabs] Good issue for external contributorstenet-performancePerformance related issuePerformance related issue