Skip to content

Commit

Permalink
Merge pull request #68 from pfpack/feature/minor-refactor
Browse files Browse the repository at this point in the history
feature/minor-refactor
  • Loading branch information
andreise authored Jan 24, 2024
2 parents da0df8a + c75ea51 commit 1d46c8e
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,13 @@ private void InnerAddRange(T[] items, int length)
Debug.Assert(length > 0 && length <= items.Length);

InnerBuilderBufferHelper.EnsureBufferCapacity(ref this.items, this.length, length);
var sourceSpan = length == items.Length
? new ReadOnlySpan<T>(items)
: new ReadOnlySpan<T>(items, 0, length);

ReadOnlySpan<T> sourceSpan = length == items.Length
? new(items)
: new(items, 0, length);

sourceSpan.CopyTo(new Span<T>(this.items, this.length, length));

this.length += length;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,13 +52,13 @@ public void CopyTo(T[] array, int arrayIndex)
return;
}

var sourceSpan = length == items.Length
? new ReadOnlySpan<T>(items)
: new ReadOnlySpan<T>(items, 0, length);
ReadOnlySpan<T> sourceSpan = length == items.Length
? new(items)
: new(items, 0, length);

var destSpan = arrayIndex == default && length == array.Length
? new Span<T>(array)
: new Span<T>(array, arrayIndex, length);
Span<T> destSpan = arrayIndex == default && length == array.Length
? new(array)
: new(array, arrayIndex, length);

sourceSpan.CopyTo(destSpan);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@ internal static T[] Copy(T[] array, int length)
{
Debug.Assert(length >= 0 && length <= array.Length);

var sourceSpan = length == array.Length
? new ReadOnlySpan<T>(array)
: new ReadOnlySpan<T>(array, 0, length);
ReadOnlySpan<T> sourceSpan = length == array.Length
? new(array)
: new(array, 0, length);
return sourceSpan.ToArray();
}

Expand All @@ -28,9 +28,9 @@ internal static T[] CopySegment(T[] array, int start, int length)
{
Debug.Assert(InnerAllocHelper.IsSegmentWithinBounds(start, length, array.Length));

var sourceSpan = start == default && length == array.Length
? new ReadOnlySpan<T>(array)
: new ReadOnlySpan<T>(array, start, length);
ReadOnlySpan<T> sourceSpan = start == default && length == array.Length
? new(array)
: new(array, start, length);
return sourceSpan.ToArray();
}

Expand All @@ -40,17 +40,19 @@ internal static T[] Concat(T[] array1, int length1, T[] array2, int length2)
Debug.Assert(length1 >= 0 && length1 <= array1.Length);
Debug.Assert(length2 >= 0 && length2 <= array2.Length);

var sourceSpan1 = length1 == array1.Length
? new ReadOnlySpan<T>(array1)
: new ReadOnlySpan<T>(array1, 0, length1);
ReadOnlySpan<T> sourceSpan1 = length1 == array1.Length
? new(array1)
: new(array1, 0, length1);

var sourceSpan2 = length2 == array2.Length
? new ReadOnlySpan<T>(array2)
: new ReadOnlySpan<T>(array2, 0, length2);
ReadOnlySpan<T> sourceSpan2 = length2 == array2.Length
? new(array2)
: new(array2, 0, length2);

var result = new T[unchecked(length1 + length2)];

var result = new T[length1 + length2];
sourceSpan1.CopyTo(new Span<T>(result, 0, length1));
sourceSpan2.CopyTo(new Span<T>(result, length1, length2));

return result;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ partial class FlatArrayJsonConverterFactory
type: typeof(FlatArray<>.JsonConverter).MakeGenericType(itemType),
bindingAttr: BindingFlags.Instance | BindingFlags.Public,
binder: null,
args: new object?[] { options },
args: [options],
culture: null);

Debug.Assert(converter is not null);
Expand Down

0 comments on commit 1d46c8e

Please sign in to comment.