Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feature/minor-refactor #68

Merged
merged 3 commits into from
Jan 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading