From 023183d727f1a1897a84c1867f1e22c574c95429 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tom=C3=A1=C5=A1=20Matou=C5=A1ek?= Date: Mon, 13 Jan 2020 14:05:57 -0800 Subject: [PATCH] Remove unused parameter and clean up MemoryMappedInfo (#40817) * Remove unused parameter and clean up MemoryMappedInfo --- ...yStorageServiceFactory.MemoryMappedInfo.cs | 106 +++++------------- 1 file changed, 30 insertions(+), 76 deletions(-) diff --git a/src/Workspaces/Core/Portable/TemporaryStorage/TemporaryStorageServiceFactory.MemoryMappedInfo.cs b/src/Workspaces/Core/Portable/TemporaryStorage/TemporaryStorageServiceFactory.MemoryMappedInfo.cs index 623e3d6fe56..445cc35b87c 100644 --- a/src/Workspaces/Core/Portable/TemporaryStorage/TemporaryStorageServiceFactory.MemoryMappedInfo.cs +++ b/src/Workspaces/Core/Portable/TemporaryStorage/TemporaryStorageServiceFactory.MemoryMappedInfo.cs @@ -1,5 +1,7 @@ // Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. +#nullable enable + using System; using System.Diagnostics; using System.IO; @@ -38,9 +40,9 @@ internal sealed class MemoryMappedInfo : IDisposable /// The memory mapped file. /// /// - /// It is possible for this accessor to be disposed prior to the view and/or the streams which use it. - /// However, the operating system does not actually close the views which are in use until the view handles - /// are closed as well, even if the is disposed first. + /// It is possible for the file to be disposed prior to the view and/or the streams which use it. + /// However, the operating system does not actually close the views which are in use until the file handles + /// are closed as well, even if the file is disposed first. /// private readonly ReferenceCountedDisposable _memoryMappedFile; @@ -89,16 +91,6 @@ public MemoryMappedInfo(string name, long offset, long size) /// public long Size { get; } - private static void ForceCompactingGC() - { - // repeated GC.Collect / WaitForPendingFinalizers till memory freed delta is super small, ignore the return value - GC.GetTotalMemory(forceFullCollection: true); - - // compact the LOH - GCSettings.LargeObjectHeapCompactionMode = GCLargeObjectHeapCompactionMode.CompactOnce; - GC.Collect(); - } - /// /// Caller is responsible for disposing the returned stream. /// multiple call of this will not increase VM. @@ -120,7 +112,7 @@ public Stream CreateReadableStream() } Debug.Assert(streamAccessor.Target.CanRead); - return new SharedReadableStream(this, streamAccessor, Size); + return new SharedReadableStream(streamAccessor, Size); } } @@ -167,6 +159,16 @@ public Stream CreateWritableStream() } } + private static void ForceCompactingGC() + { + // repeated GC.Collect / WaitForPendingFinalizers till memory freed delta is super small, ignore the return value + GC.GetTotalMemory(forceFullCollection: true); + + // compact the LOH + GCSettings.LargeObjectHeapCompactionMode = GCLargeObjectHeapCompactionMode.CompactOnce; + GC.Collect(); + } + public void Dispose() { // See remarks on field for relation between _memoryMappedFile and the views/streams. There is no @@ -182,44 +184,17 @@ private unsafe sealed class SharedReadableStream : Stream, ISupportDirectMemoryA private byte* _current; private readonly byte* _end; - public SharedReadableStream(MemoryMappedInfo owner, ReferenceCountedDisposable accessor, long length) + public SharedReadableStream(ReferenceCountedDisposable accessor, long length) { _accessor = accessor; _current = _start = (byte*)_accessor.Target.SafeMemoryMappedViewHandle.DangerousGetHandle() + _accessor.Target.PointerOffset; _end = checked(_start + length); } - public override bool CanRead - { - get - { - return true; - } - } - - public override bool CanSeek - { - get - { - return true; - } - } - - public override bool CanWrite - { - get - { - return false; - } - } - - public override long Length - { - get - { - return _end - _start; - } - } + public override bool CanRead => true; + public override bool CanSeek => true; + public override bool CanWrite => false; + public override long Length => _end - _start; public override long Position { @@ -270,23 +245,13 @@ public override long Seek(long offset, SeekOrigin origin) byte* target; try { - switch (origin) + target = origin switch { - case SeekOrigin.Begin: - target = checked(_start + offset); - break; - - case SeekOrigin.Current: - target = checked(_current + offset); - break; - - case SeekOrigin.End: - target = checked(_end + offset); - break; - - default: - throw new ArgumentOutOfRangeException(nameof(origin)); - } + SeekOrigin.Begin => checked(_start + offset), + SeekOrigin.Current => checked(_current + offset), + SeekOrigin.End => checked(_end + offset), + _ => throw new ArgumentOutOfRangeException(nameof(origin)), + }; } catch (OverflowException) { @@ -302,20 +267,9 @@ public override long Seek(long offset, SeekOrigin origin) return _current - _start; } - public override void Flush() - { - throw new NotSupportedException(); - } - - public override void SetLength(long value) - { - throw new NotSupportedException(); - } - - public override void Write(byte[] buffer, int offset, int count) - { - throw new NotSupportedException(); - } + public override void Flush() => throw new NotSupportedException(); + public override void SetLength(long value) => throw new NotSupportedException(); + public override void Write(byte[] buffer, int offset, int count) => throw new NotSupportedException(); protected override void Dispose(bool disposing) { -- GitLab