-
-
Notifications
You must be signed in to change notification settings - Fork 108
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
Support Span<T> conversion #29
Conversation
@@ -682,21 +691,24 @@ string outputDirectory | |||
string line; | |||
while (null != (line = input.ReadLine())) | |||
{ | |||
foreach (var replacement in replacements) | |||
// Replacing longer matches first is a safeguard heuristic. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Everything below this line is just refactoring that creeped into this PR
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please see my comments.
And please check the template here: https://github.com/nanoframework/CoreLibrary/blob/develop/nanoFramework.CoreLibrary/System/SpanByte.cs
{ | ||
if (array != null) | ||
{ | ||
if ((start + length > array.Length) || (start >= array.Length)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should be this: if ((length > array.Length - start) || (start > array.Length))
Check things here: https://github.com/nanoframework/CoreLibrary/blob/develop/nanoFramework.CoreLibrary/System/SpanByte.cs
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can start be equal to array length, unless length=0?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks correct:
if (start < 0 ||
length < 0 ||
start + length > array.Length ||
(start == array.Length && array.Length > 0))
{ | ||
get | ||
{ | ||
int realIndex = _start + index; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the get should be:
if (index > _length)
{
throw new ArgumentOutOfRangeException(); }
}
return _array[_start + index];
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, I see. Length is not the length of the array.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
By the way it's >=
, not >
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good catch for this one. Mind a PR on mscorlib? :-)
|
||
set | ||
{ | ||
int realIndex = _start + index; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
set should be:
if (index > _length)
{
throw new ArgumentOutOfRangeException();
}
_array[_start + index] = value;
/// <exception cref="System.ArgumentOutOfRangeException">start is less than zero or greater than System.Span.Length.</exception> | ||
public Span<T> Slice(int start) | ||
{ | ||
return Slice(start, _length - start); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
missing the check for the length
if ((start > _length) || (start < 0))
{
throw new ArgumentOutOfRangeException();
}
return new SpanByte(_array, _start + start, _length - start);
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It should check it in the "main" metod Slice(start, length)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fair
/// Defines an implicit conversion of a System.Span to a System.ReadOnlySpan. | ||
/// </summary> | ||
/// <param name="span">The object to convert to a System.ReadOnlySpan.</param> | ||
public static implicit operator ReadOnlySpan<T>(Span<T> span) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
remove this one, we don't need ReadOnlySpan, we've simplify and get read of the ReadOnlySpan to only have Span
|
If I see it right, SpanByte in mscorlib currently has a bug and allows access 1 cell beyond the available length. If the version in this PR looks good, I can move it to core library. |
/// <exception cref="System.ArgumentOutOfRangeException">start is less than zero or greater than System.Span.Length.</exception> | ||
public Span<T> Slice(int start) | ||
{ | ||
return Slice(start, _length - start); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fair
@gukoff thanks! do you mind resolving the conflicts so we can merge this one soon? |
Head branch was pushed to by a user without write access
Description
Support Span conversion.
REVIEW THE FIRST COMMIT
Motivation and Context
No support existed before.
How Has This Been Tested?
Verified regenerated projects work in Visual Studio.
Screenshots
Types of changes
Checklist: