// touch the file pointer location at all. We will adjust it
// ourselves, but only in memory. This isn't threadsafe.
_filePosition += destination.Length;
+
+ // We know for sure that there is nothing to read, so we just return here and avoid a sys-call.
+ if (destination.IsEmpty && LengthCachingSupported)
+ {
+ return ValueTask.FromResult(0);
+ }
}
(SafeFileHandle.OverlappedValueTaskSource? vts, int errorCode) = RandomAccess.QueueAsyncReadFile(_fileHandle, destination, positionBefore, cancellationToken);
}
}
- private bool LengthCachingSupported => OperatingSystem.IsWindows() && _share <= FileShare.Read && !_exposedHandle;
+ protected bool LengthCachingSupported => OperatingSystem.IsWindows() && _share <= FileShare.Read && !_exposedHandle;
/// <summary>Gets or sets the position within the current stream</summary>
public sealed override long Position