Move memory-mapped-text storage system to use the new pattern introduced for memory-mapped-stream storage.#73218
Conversation
|
|
||
| internal sealed partial class TemporaryStorageService | ||
| { | ||
| private unsafe class DirectMemoryAccessStreamReader : TextReaderWithLength |
There was a problem hiding this comment.
Just a move into its own file. this didn't change at all (besides becoming nested and private).
| /// <summary> | ||
| /// TemporaryStorage can be used to read and write text to a temporary storage location. | ||
| /// </summary> | ||
| internal interface ITemporaryTextStorageInternal |
| /// <summary> | ||
| /// TemporaryStorage can be used to read and write text to a temporary storage location. | ||
| /// </summary> | ||
| internal interface ITemporaryStorageWithName |
| /// The <see cref="SourceText"/> in the current process. | ||
| /// </summary> | ||
| /// <remarks> | ||
| /// <inheritdoc cref="Storage"/> |
There was a problem hiding this comment.
This was referencing the namespace... whoopsie :)
| var identifier = new TemporaryStorageIdentifier(memoryMappedInfo.Name, memoryMappedInfo.Offset, memoryMappedInfo.Size); | ||
| return new(this, memoryMappedInfo.MemoryMappedFile, identifier, text.ChecksumAlgorithm, text.Encoding, text.GetContentHash()); | ||
|
|
||
| MemoryMappedInfo WriteToMemoryMappedFile() |
There was a problem hiding this comment.
this code was inlined from the old TemporaryTextStorage type (which was deleted).
| var identifier = new TemporaryStorageIdentifier(memoryMappedInfo.Name, memoryMappedInfo.Offset, memoryMappedInfo.Size); | ||
| return new(memoryMappedInfo.MemoryMappedFile, identifier); | ||
|
|
||
| MemoryMappedInfo WriteToMemoryMappedFile() |
There was a problem hiding this comment.
this code was inlined from TemporaryStreamStorage (which was itself deleted).
| } | ||
| } | ||
|
|
||
| internal unsafe class DirectMemoryAccessStreamReader : TextReaderWithLength |
There was a problem hiding this comment.
moved to new file.
| } | ||
| } | ||
|
|
||
| internal sealed class TemporaryStreamStorage |
There was a problem hiding this comment.
this abstraction just wasnt' necessary. i inlined it all into the one caller.
|
|
||
| var info = new MemoryMappedInfo(memoryMappedFile, Identifier.Name, Identifier.Offset, Identifier.Size); | ||
| return info.CreateReadableStream(); | ||
| } |
There was a problem hiding this comment.
this is just the old storage.ReadStream method inlined (so we could delete TemporaryStreamStorage).
| { | ||
| await Task.Yield().ConfigureAwait(false); | ||
| cancellationToken.ThrowIfCancellationRequested(); | ||
| } |
There was a problem hiding this comment.
existing logic. just inlined.
| Task WriteStreamAsync(Stream stream, CancellationToken cancellationToken = default); | ||
| } | ||
|
|
||
| /// <summary> |
There was a problem hiding this comment.
Have the interfaces and their implementations above been obsoleted long enough for removal?
There was a problem hiding this comment.
We have to make then Obsolete(error: true) first. i can do that in a followup.
src/Workspaces/Core/Portable/Workspace/Host/TemporaryStorage/ITemporaryStorageService.cs
Show resolved
Hide resolved
|
|
||
| namespace Microsoft.CodeAnalysis.Host; | ||
|
|
||
| internal interface ITemporaryStorageTextHandle |
There was a problem hiding this comment.
It almost seems like there could just be a single
ITemporaryStorageHandle interface that returned TStorage from the Read* methods
There was a problem hiding this comment.
Maybe? I just don't see it buying much . This isn't a system we've needed to generalize. It handles byte streams and encoded strings effectively. I'm fine keeping it specific to those two needs.
| { | ||
| // Return a read-only view of the underlying buffer to prevent users from overwriting or directly | ||
| // disposing the backing storage. | ||
| return new MemoryStream(streamCopy.GetBuffer(), 0, (int)streamCopy.Length, writable: false); |
There was a problem hiding this comment.
Does this method not get called on many of the TrivialStorageStreamHandle instance created? If it's called on most/all of them, it seems like this could just be stored in the field.
If the earlier comment about combining the interfaces into ITemporaryStorageHandle were used, and if the caller would just pass in an appopriate read only stream, then the stream/text versions of these classes could be combined too.
There was a problem hiding this comment.
I'm preserving the behavior from before. I'm genuinely not sure if we have a single scenario exercising this code in the real world, so I'd prefer to leave the semantics as is for safety.
| => "Roslyn Temp Storage " + size.ToString() + " " + Guid.NewGuid().ToString("N"); | ||
|
|
||
| public sealed class TemporaryTextStorage : ITemporaryTextStorageInternal, ITemporaryStorageWithName | ||
| public sealed class TemporaryStorageTextHandle( |
| public override int Peek() | ||
| { | ||
| if (_position >= _end) | ||
| { |
|
@jasonmalinowski for review when you get back. |
Updates to follow the patterns here: #73115
Followup to: #73216