Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

CyrusNajmabadi
Copy link
Member

No description provided.

@CyrusNajmabadi CyrusNajmabadi requested a review from a team as a code owner January 31, 2024 04:41
@ghost ghost added Area-IDE untriaged Issues and PRs which have not yet been triaged by a lead labels Jan 31, 2024
{
// char pooled memory : 8K * 256 = 2MB
private const int CharBufferSize = 4 * 1024;
private static readonly ObjectPool<char[]> CharArrayPool = new(() => new char[CharBufferSize], 256);
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

moved these here as this is the only place it is used. and it is easier to validate proper usage.

writer.WriteInt32(numberOfChunks);

// write whole chunks
try
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

view with whitespace off.

var elementType = typeof(byte);
Debug.Assert(s_typeMap[elementType] == TypeCode.UInt8);
var elementType = typeof(T);
Contract.ThrowIfFalse(s_typeMap.ContainsKey(elementType));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

s_typeMap

TryGetValue to avoid duplicated lookup?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i don't mind this too much. so we get a nice contract failure if we defy expectations here.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not a big deal, but not sure why this is less clear:

Contract.ThrowIfFalse(s_typeMap.TryGetValue(elementType, out var actualType));
Contract.ThrowIfTrue(expectedType != actualType);

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ah, misunderstood. yes, that's nicer. will do in followup.

}

/// <summary>
/// Write an array of bytes. The array data is provided as a <see
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

bytes

nit: chars

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can fix in followup :)

Action<BinaryWriter, T[], int> write)
{
var spanLength = span.Length;
var buffer = System.Buffers.ArrayPool<T>.Shared.Rent(Math.Min(spanLength, rentLength));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

System.Buffers.ArrayPool

I'm curious why you chose to use System.Buffer.ArrayPools instead of ArrayBuilder

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

offline: for straight IO buffers, this feels more in line with what the runtime does.

/// </summary>
/// <param name="span">The array data.</param>
public void WriteValue(ReadOnlySpan<byte> span)
public void WriteSpan(ReadOnlySpan<byte> span)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

public void WriteSpan(ReadOnlySpan span)

Just going to mention it in the PR for posterity, but would be nice if we wouldn't need to write the preamble for every chunk we want persisted.

Copy link
Contributor

@ToddGrun ToddGrun left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

:shipit:

@CyrusNajmabadi CyrusNajmabadi merged commit fd51297 into dotnet:main Feb 1, 2024
@ghost ghost added this to the Next milestone Feb 1, 2024
@CyrusNajmabadi CyrusNajmabadi deleted the sourceTextAllocate branch February 1, 2024 19:15
@jjonescz jjonescz modified the milestones: Next, 17.10 P2 Feb 27, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area-IDE untriaged Issues and PRs which have not yet been triaged by a lead
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants