Skip to content

Commit

Permalink
Add ValueMemoryOwner
Browse files Browse the repository at this point in the history
  • Loading branch information
aalmada committed May 12, 2021
1 parent 7c97136 commit 0ada4fb
Show file tree
Hide file tree
Showing 75 changed files with 388 additions and 530 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public static MethodInfo GetInfo(this IMethodSymbol method, CompilationContext c
Name = method.Name,
Parameters = method.Parameters
.Skip(skip)
.Select(parameter => (parameter.Name, parameter.Type.ToDisplayString(), parameter.HasExplicitDefaultValue ? (parameter.ExplicitDefaultValue is null ? "default" : parameter.ExplicitDefaultValue.ToString()) : default))
.Select(parameter => (parameter.Name, parameter.Type.ToDisplayString(), parameter.HasExplicitDefaultValue ? parameter.ExplicitDefaultValue is null ? "default" : ToDisplayString(parameter.ExplicitDefaultValue) : default))
.ToArray(),
TypeParameters =
method.ContainingType.TypeParameters.Concat(method.TypeParameters)
Expand All @@ -53,6 +53,15 @@ public static MethodInfo GetInfo(this IMethodSymbol method, CompilationContext c
{
throw;
}

string ToDisplayString(object? obj)
=> obj switch
{
null => "<NULL>",
true => "true",
false => "false",
_ => obj.ToString()
};
}

public static MethodInfo ApplyMappings(this MethodInfo method, ImmutableArray<GeneratorMappingAttribute> typeGenericsMapping)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ public static IEnumerable<INamedTypeSymbol> GetAllInterfaces(this ITypeSymbol ty
yield return (INamedTypeSymbol)typeSymbol;

#pragma warning disable IDE0007 // Use implicit type
// ReSharper disable once SuggestVarOrType_SimpleTypes
ITypeSymbol? currentTypeSymbol = typeSymbol;
#pragma warning restore IDE0007 // Use implicit type
do
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public void ToArray_Must_Succeed(int count)
var expected = Enumerable
.Range(0, count)
.ToArray();
using var builder = new LargeArrayBuilder<int>(ArrayPool<int>.Shared);
using var builder = new LargeArrayBuilder<int>(ArrayPool<int>.Shared, false);
for (var index = 0; index < count; index++)
builder.Add(expected[index]);

Expand All @@ -39,16 +39,16 @@ public void ToArray_Must_Succeed(int count)
public void ToArray_MemoryPool_Must_Succeed(int count)
{
// Arrange
var pool = MemoryPool<int>.Shared;
var pool = ArrayPool<int>.Shared;
var expected = Enumerable
.Range(0, count)
.ToArray();
using var builder = new LargeArrayBuilder<int>(ArrayPool<int>.Shared);
using var builder = new LargeArrayBuilder<int>(ArrayPool<int>.Shared, false);
for (var index = 0; index < count; index++)
builder.Add(expected[index]);

// Act
using var result = builder.ToArray(pool);
using var result = builder.ToArray(pool, false);

// Assert
_ = result.Memory.Must()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public void ToArray_Must_Succeed(int[] source, int skip, int take)
public void ToArray_MemoryPool_Must_Succeed(int[] source, int skip, int take)
{
// Arrange
var pool = MemoryPool<int>.Shared;
var pool = ArrayPool<int>.Shared;
var wrapped = Wrap.AsReadOnlyList(source);
var expected = source
.Skip(skip)
Expand Down Expand Up @@ -100,7 +100,7 @@ public void ToArray_Predicate_Must_Succeed(int[] source, int skip, int take, Fun
public void ToArray_Predicate_MemoryPool_Must_Succeed(int[] source, int skip, int take, Func<int, bool> predicate)
{
// Arrange
var pool = MemoryPool<int>.Shared;
var pool = ArrayPool<int>.Shared;
var wrapped = Wrap.AsReadOnlyList(source);
var expected = source
.Skip(skip)
Expand Down Expand Up @@ -159,7 +159,7 @@ public void ToArray_PredicateAt_Must_Succeed(int[] source, int skip, int take, F
public void ToArray_PredicateAt_MemoryPool_Must_Succeed(int[] source, int skip, int take, Func<int, int, bool> predicate)
{
// Arrange
var pool = MemoryPool<int>.Shared;
var pool = ArrayPool<int>.Shared;
var wrapped = Wrap.AsReadOnlyList(source);
var expected = source
.Skip(skip)
Expand Down Expand Up @@ -217,7 +217,7 @@ public void ToArray_Selector_Must_Succeed(int[] source, int skip, int take, Func
public void ToArray_Selector_MemoryPool_Must_Succeed(int[] source, int skip, int take, Func<int, string> selector)
{
// Arrange
var pool = MemoryPool<string>.Shared;
var pool = ArrayPool<string>.Shared;
var wrapped = Wrap.AsReadOnlyList(source);
var expected = source
.Skip(skip)
Expand Down Expand Up @@ -275,7 +275,7 @@ public void ToArray_SelectorAt_Must_Succeed(int[] source, int skip, int take, Fu
public void ToArray_SelectorAt_MemoryPool_Must_Succeed(int[] source, int skip, int take, Func<int, int, string> selector)
{
// Arrange
var pool = MemoryPool<string>.Shared;
var pool = ArrayPool<string>.Shared;
var wrapped = Wrap.AsReadOnlyList(source);
var expected = source
.Skip(skip)
Expand Down Expand Up @@ -335,7 +335,7 @@ public void ToArray_Predicate_Selector_Must_Succeed(int[] source, int skip, int
public void ToArray_Predicate_Selector_MemoryPool_Must_Succeed(int[] source, int skip, int take, Func<int, bool> predicate, Func<int, string> selector)
{
// Arrange
var pool = MemoryPool<string>.Shared;
var pool = ArrayPool<string>.Shared;
var wrapped = Wrap.AsReadOnlyList(source);
var expected = source
.Skip(skip)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public void ToArray_MemoryPool_Must_Succeed(int[] source)
{
// Arrange
var wrapped = (ReadOnlySpan<int>)source.AsSpan();
var pool = MemoryPool<int>.Shared;
var pool = ArrayPool<int>.Shared;
var expected = source
.ToArray();

Expand Down Expand Up @@ -66,7 +66,7 @@ public void ToArray_Predicate_MemoryPool_Must_Succeed(int[] source, Func<int, bo
{
// Arrange
var wrapped = (ReadOnlySpan<int>)source.AsSpan();
var pool = MemoryPool<int>.Shared;
var pool = ArrayPool<int>.Shared;
var expected = source
.Where(predicate)
.ToArray();
Expand Down Expand Up @@ -117,7 +117,7 @@ public void ToArray_PredicateAt_MemoryPool_Must_Succeed(int[] source, Func<int,
{
// Arrange
var wrapped = (ReadOnlySpan<int>)source.AsSpan();
var pool = MemoryPool<int>.Shared;
var pool = ArrayPool<int>.Shared;
var expected = source
.Where(predicate)
.ToArray();
Expand Down Expand Up @@ -167,7 +167,7 @@ public void ToArray_Selector_MemoryPool_Must_Succeed(int[] source, Func<int, str
{
// Arrange
var wrapped = (ReadOnlySpan<int>)source.AsSpan();
var pool = MemoryPool<string>.Shared;
var pool = ArrayPool<string>.Shared;
var expected = source
.Select(selector)
.ToArray();
Expand Down Expand Up @@ -217,7 +217,7 @@ public void ToArray_SelectorAt_MemoryPool_Must_Succeed(int[] source, Func<int, i
{
// Arrange
var wrapped = (ReadOnlySpan<int>)source.AsSpan();
var pool = MemoryPool<string>.Shared;
var pool = ArrayPool<string>.Shared;
var expected = source
.Select(selector)
.ToArray();
Expand Down Expand Up @@ -269,7 +269,7 @@ public void ToArray_Predicate_Selector_MemoryPool_Must_Succeed(int[] source, Fun
{
// Arrange
var wrapped = (ReadOnlySpan<int>)source.AsSpan();
var pool = MemoryPool<string>.Shared;
var pool = ArrayPool<string>.Shared;
var expected = source
.Where(predicate)
.Select(selector)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ public void ToArray_With_ValidData_Collections_Must_Succeed(int[] source)
public void ToArray_MemoryPool_Must_Succeed(int[] source)
{
// Arrange
var pool = MemoryPool<int>.Shared;
var pool = ArrayPool<int>.Shared;
var wrapped = Wrap
.AsValueEnumerable(source);
var expected = source
Expand Down Expand Up @@ -107,7 +107,7 @@ public void ToArray_Predicate_With_ValidData_Must_Succeed(int[] source, Func<int
public void ToArray_Predicate_MemoryPool_Must_Succeed(int[] source, Func<int, bool> predicate)
{
// Arrange
var pool = MemoryPool<int>.Shared;
var pool = ArrayPool<int>.Shared;
var wrapped = Wrap
.AsValueEnumerable(source);
var expected = source
Expand Down Expand Up @@ -157,7 +157,7 @@ public void ToArray_PredicateAt_With_ValidData_Must_Succeed(int[] source, Func<i
public void ToArray_PredicateAt_MemoryPool_With_ValidData_Must_Succeed(int[] source, Func<int, int, bool> predicate)
{
// Arrange
var pool = MemoryPool<int>.Shared;
var pool = ArrayPool<int>.Shared;
var wrapped = Wrap
.AsValueEnumerable(source);
var expected = source
Expand Down Expand Up @@ -207,7 +207,7 @@ public void ToArray_Selector_With_ValidData_Must_Succeed(int[] source, Func<int,
public void ToArray_Selector_MemoryPool_With_ValidData_Must_Succeed(int[] source, Func<int, string> selector)
{
// Arrange
var pool = MemoryPool<string>.Shared;
var pool = ArrayPool<string>.Shared;
var wrapped = Wrap
.AsValueEnumerable(source);
var expected = source
Expand Down Expand Up @@ -257,7 +257,7 @@ public void ToArray_SelectorAt_With_ValidData_Must_Succeed(int[] source, Func<in
public void ToArray_SelectorAt_MemoryPool_With_ValidData_Must_Succeed(int[] source, Func<int, int, string> selector)
{
// Arrange
var pool = MemoryPool<string>.Shared;
var pool = ArrayPool<string>.Shared;
var wrapped = Wrap
.AsValueEnumerable(source);
var expected = source
Expand Down Expand Up @@ -309,7 +309,7 @@ public void ToArray_Predicate_Selector_With_ValidData_Must_Succeed(int[] source,
public void ToArray_Predicate_Selector_MemoryPool_With_ValidData_Must_Succeed(int[] source, Func<int, bool> predicate, Func<int, string> selector)
{
// Arrange
var pool = MemoryPool<string>.Shared;
var pool = ArrayPool<string>.Shared;
var wrapped = Wrap
.AsValueEnumerable(source);
var expected = source
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ public void ToArray_With_ValidData_Collections_Must_Succeed(int[] source)
public void ToArray_MemoryPool_Must_Succeed(int[] source)
{
// Arrange
var pool = MemoryPool<int>.Shared;
var pool = ArrayPool<int>.Shared;
var wrapped = Wrap
.AsValueReadOnlyCollection(source);
var expected = source
Expand Down Expand Up @@ -107,7 +107,7 @@ public void ToArray_Predicate_With_ValidData_Must_Succeed(int[] source, Func<int
public void ToArray_Predicate_MemoryPool_With_ValidData_Must_Succeed(int[] source, Func<int, string> selector)
{
// Arrange
var pool = MemoryPool<string>.Shared;
var pool = ArrayPool<string>.Shared;
var wrapped = Wrap
.AsValueReadOnlyCollection(source);
var expected = source
Expand Down Expand Up @@ -157,7 +157,7 @@ public void ToArray_SelectorAt_With_ValidData_Must_Succeed(int[] source, Func<in
public void ToArray_SelectorAt_MemoryPool_With_ValidData_Must_Succeed(int[] source, Func<int, int, string> selector)
{
// Arrange
var pool = MemoryPool<string>.Shared;
var pool = ArrayPool<string>.Shared;
var wrapped = Wrap
.AsValueReadOnlyCollection(source);
var expected = source
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public async ValueTask ToArrayAsync_With_ValidData_Must_Succeed(int[] source)
public async ValueTask ToArrayAsync_MemoryPool_Must_Succeed(int[] source)
{
// Arrange
var pool = MemoryPool<int>.Shared;
var pool = ArrayPool<int>.Shared;
var wrapped = Wrap
.AsAsyncValueEnumerable(source);
var expected = source
Expand Down Expand Up @@ -89,7 +89,7 @@ public async ValueTask ToArrayAsync_Predicate_With_ValidData_Must_Succeed(int[]
public async ValueTask ToArrayAsync_Predicate_MemoryPool_Must_Succeed(int[] source, Func<int, bool> predicate)
{
// Arrange
var pool = MemoryPool<int>.Shared;
var pool = ArrayPool<int>.Shared;
var wrapped = Wrap
.AsAsyncValueEnumerable(source);
var expected = source
Expand Down Expand Up @@ -141,7 +141,7 @@ public async ValueTask ToArrayAsync_PredicateAt_With_ValidData_Must_Succeed(int[
public async ValueTask ToArrayAsync_PredicateAt_MemoryPool_Must_Succeed(int[] source, Func<int, int, bool> predicate)
{
// Arrange
var pool = MemoryPool<int>.Shared;
var pool = ArrayPool<int>.Shared;
var wrapped = Wrap
.AsAsyncValueEnumerable(source);
var expected = source
Expand Down Expand Up @@ -193,7 +193,7 @@ public async ValueTask ToArrayAsync_Selector_With_ValidData_Must_Succeed(int[] s
public async ValueTask ToArrayAsync_Selector_MemoryPool_Must_Succeed(int[] source, Func<int, string> selector)
{
// Arrange
var pool = MemoryPool<string>.Shared;
var pool = ArrayPool<string>.Shared;
var wrapped = Wrap
.AsAsyncValueEnumerable(source);
var expected = source
Expand Down Expand Up @@ -245,7 +245,7 @@ public async ValueTask ToArrayAsync_SelectorAt_With_ValidData_Must_Succeed(int[]
public async ValueTask ToArrayAsync_SelectorAt_MemoryPool_Must_Succeed(int[] source, Func<int, int, string> selector)
{
// Arrange
var pool = MemoryPool<string>.Shared;
var pool = ArrayPool<string>.Shared;
var wrapped = Wrap
.AsAsyncValueEnumerable(source);
var expected = source
Expand Down Expand Up @@ -300,7 +300,7 @@ public async ValueTask ToArrayAsync_Predicate_Selector_With_ValidData_Must_Succe
public async ValueTask ToArrayAsync_Predicate_Selector_MemoryPool_Must_Succeed(int[] source, Func<int, bool> predicate, Func<int, string> selector)
{
// Arrange
var pool = MemoryPool<string>.Shared;
var pool = ArrayPool<string>.Shared;
var wrapped = Wrap
.AsAsyncValueEnumerable(source);
var expected = source
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ public void Distinct_ToArray_With_ValidData_Must_Succeed(int[] source, int skip,
public void Distinct_ToArray_MemoryPool_With_ValidData_Must_Succeed(int[] source, int skip, int take)
{
// Arrange
var pool = MemoryPool<int>.Shared;
var pool = ArrayPool<int>.Shared;
var (offset, count) = Utils.SkipTake(source.Length, skip, take);
var wrapped = new ArraySegment<int>(source, offset, count);
var expected = wrapped
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ public async ValueTask Distinct_ToArrayAsync_With_ValidData_Must_Succeed(int[] s
public async ValueTask Distinct_ToArrayAsync_MemoryPool_With_ValidData_Must_Succeed(int[] source)
{
// Arrange
var pool = MemoryPool<int>.Shared;
var pool = ArrayPool<int>.Shared;
var wrapped = Wrap.AsAsyncValueEnumerable(source);
var expected = source
.Distinct()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ public void Distinct_ToArray_With_ValidData_Must_Succeed(int[] source, int skip,
public void Distinct_ToArray_MemoryPool_With_ValidData_Must_Succeed(int[] source, int skip, int take)
{
// Arrange
var pool = MemoryPool<int>.Shared;
var pool = ArrayPool<int>.Shared;
var wrapped = Wrap.AsReadOnlyList(source);
var expected = source
.Skip(skip)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ public void Distinct_ToArray_With_ValidData_Must_Succeed(int[] source)
public void Distinct_ToArray_MemoryPool_With_ValidData_Must_Succeed(int[] source)
{
// Arrange
var pool = MemoryPool<int>.Shared;
var pool = ArrayPool<int>.Shared;
var wrapped = (ReadOnlyMemory<int>)source.AsMemory();
var expected = source
.Distinct()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ public void Distinct_ToArray_MemoryPool_With_ValidData_Must_Succeed(int[] source
// Act
using var result = wrapped.AsValueEnumerable()
.Distinct()
.ToArray(MemoryPool<int>.Shared);
.ToArray(ArrayPool<int>.Shared);

// Assert
_ = result.Memory.Must()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ public void Distinct_ToArray_With_ValidData_Must_Succeed(int[] source)
public void Distinct_ToArray_MemoryPool_With_ValidData_Must_Succeed(int[] source)
{
// Arrange
var pool = MemoryPool<int>.Shared;
var pool = ArrayPool<int>.Shared;
var wrapped = Wrap.AsValueEnumerable(source);
var expected = source
.Distinct()
Expand Down
Loading

0 comments on commit 0ada4fb

Please sign in to comment.