Skip to content
This repository has been archived by the owner on Nov 1, 2020. It is now read-only.

Commit

Permalink
Merge pull request dotnet/coreclr#16091 from dotnet-maestro-bot/maste…
Browse files Browse the repository at this point in the history
…r-UpdateDependencies

Update BuildTools, CoreClr, CoreFx, PgoData to prerelease-02430-04, preview2-26130-05, preview2-26130-01, master-20180130-0046, respectively (master)

Signed-off-by: dotnet-bot <dotnet-bot@microsoft.com>
  • Loading branch information
jkotas committed Feb 2, 2018
1 parent 8348bb2 commit 497acea
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 108 deletions.
28 changes: 2 additions & 26 deletions src/System.Private.CoreLib/shared/System/ReadOnlySpan.cs
Original file line number Diff line number Diff line change
Expand Up @@ -102,19 +102,6 @@ public unsafe ReadOnlySpan(void* pointer, int length)
_length = length;
}

/// <summary>
/// Create a new read-only span over a portion of a regular managed object. This can be useful
/// if part of a managed object represents a "fixed array." This is dangerous because neither the
/// <paramref name="length"/> is checked, nor <paramref name="obj"/> being null, nor the fact that
/// "rawPointer" actually lies within <paramref name="obj"/>.
/// </summary>
/// <param name="obj">The managed object that contains the data to span over.</param>
/// <param name="objectData">A reference to data within that object.</param>
/// <param name="length">The number of <typeparamref name="T"/> elements the memory contains.</param>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
[EditorBrowsable(EditorBrowsableState.Never)]
public static ReadOnlySpan<T> DangerousCreate(object obj, ref T objectData, int length) => new ReadOnlySpan<T>(ref objectData, length);

// Constructor for internal use only.
[MethodImpl(MethodImplOptions.AggressiveInlining)]
internal ReadOnlySpan(ref T ptr, int length)
Expand All @@ -125,17 +112,6 @@ internal ReadOnlySpan(ref T ptr, int length)
_length = length;
}

/// <summary>
/// Returns a reference to the 0th element of the Span. If the Span is empty, returns a reference to the location where the 0th element
/// would have been stored. Such a reference can be used for pinning but must never be dereferenced.
/// </summary>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
[EditorBrowsable(EditorBrowsableState.Never)]
internal ref readonly T DangerousGetPinnableReference()
{
return ref _pointer.Value;
}

/// <summary>
/// The number of items in the read-only span.
/// </summary>
Expand Down Expand Up @@ -207,7 +183,7 @@ public void CopyTo(Span<T> destination)

if ((uint)_length <= (uint)destination.Length)
{
Buffer.Memmove(ref destination.DangerousGetPinnableReference(), ref _pointer.Value, (nuint)_length);
Buffer.Memmove(ref destination._pointer.Value, ref _pointer.Value, (nuint)_length);
}
else
{
Expand All @@ -227,7 +203,7 @@ public bool TryCopyTo(Span<T> destination)
bool retVal = false;
if ((uint)_length <= (uint)destination.Length)
{
Buffer.Memmove(ref destination.DangerousGetPinnableReference(), ref _pointer.Value, (nuint)_length);
Buffer.Memmove(ref destination._pointer.Value, ref _pointer.Value, (nuint)_length);
retVal = true;
}
return retVal;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,6 @@ public static Memory<T> AsMemory<T>(ReadOnlyMemory<T> readOnlyMemory) =>
/// <exception cref="System.ArgumentException">
/// Thrown when <typeparamref name="TFrom"/> or <typeparamref name="TTo"/> contains pointers.
/// </exception>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static Span<TTo> Cast<TFrom, TTo>(Span<TFrom> source)
where TFrom : struct
where TTo : struct
Expand All @@ -61,7 +60,7 @@ public static Span<TTo> Cast<TFrom, TTo>(Span<TFrom> source)
ThrowHelper.ThrowInvalidTypeWithPointersNotSupported(typeof(TTo));

return new Span<TTo>(
ref Unsafe.As<TFrom, TTo>(ref source.DangerousGetPinnableReference()),
ref Unsafe.As<TFrom, TTo>(ref source._pointer.Value),
checked((int)((long)source.Length * Unsafe.SizeOf<TFrom>() / Unsafe.SizeOf<TTo>())));
}

Expand All @@ -76,7 +75,6 @@ ref Unsafe.As<TFrom, TTo>(ref source.DangerousGetPinnableReference()),
/// <exception cref="System.ArgumentException">
/// Thrown when <typeparamref name="TFrom"/> or <typeparamref name="TTo"/> contains pointers.
/// </exception>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static ReadOnlySpan<TTo> Cast<TFrom, TTo>(ReadOnlySpan<TFrom> source)
where TFrom : struct
where TTo : struct
Expand Down
52 changes: 0 additions & 52 deletions src/System.Private.CoreLib/shared/System/Span.NonGeneric.cs
Original file line number Diff line number Diff line change
Expand Up @@ -131,58 +131,6 @@ ref Unsafe.As<T, byte>(ref MemoryMarshal.GetReference(source)),
checked(source.Length * Unsafe.SizeOf<T>()));
}

/// <summary>
/// Casts a Span of one primitive type <typeparamref name="TFrom"/> to another primitive type <typeparamref name="TTo"/>.
/// These types may not contain pointers or references. This is checked at runtime in order to preserve type safety.
/// </summary>
/// <remarks>
/// Supported only for platforms that support misaligned memory access.
/// </remarks>
/// <param name="source">The source slice, of type <typeparamref name="TFrom"/>.</param>
/// <exception cref="System.ArgumentException">
/// Thrown when <typeparamref name="TFrom"/> or <typeparamref name="TTo"/> contains pointers.
/// </exception>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static Span<TTo> NonPortableCast<TFrom, TTo>(this Span<TFrom> source)
where TFrom : struct
where TTo : struct
{
if (RuntimeHelpers.IsReferenceOrContainsReferences<TFrom>())
ThrowHelper.ThrowInvalidTypeWithPointersNotSupported(typeof(TFrom));
if (RuntimeHelpers.IsReferenceOrContainsReferences<TTo>())
ThrowHelper.ThrowInvalidTypeWithPointersNotSupported(typeof(TTo));

return new Span<TTo>(
ref Unsafe.As<TFrom, TTo>(ref source.DangerousGetPinnableReference()),
checked((int)((long)source.Length * Unsafe.SizeOf<TFrom>() / Unsafe.SizeOf<TTo>())));
}

/// <summary>
/// Casts a ReadOnlySpan of one primitive type <typeparamref name="TFrom"/> to another primitive type <typeparamref name="TTo"/>.
/// These types may not contain pointers or references. This is checked at runtime in order to preserve type safety.
/// </summary>
/// <remarks>
/// Supported only for platforms that support misaligned memory access.
/// </remarks>
/// <param name="source">The source slice, of type <typeparamref name="TFrom"/>.</param>
/// <exception cref="System.ArgumentException">
/// Thrown when <typeparamref name="TFrom"/> or <typeparamref name="TTo"/> contains pointers.
/// </exception>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static ReadOnlySpan<TTo> NonPortableCast<TFrom, TTo>(this ReadOnlySpan<TFrom> source)
where TFrom : struct
where TTo : struct
{
if (RuntimeHelpers.IsReferenceOrContainsReferences<TFrom>())
ThrowHelper.ThrowInvalidTypeWithPointersNotSupported(typeof(TFrom));
if (RuntimeHelpers.IsReferenceOrContainsReferences<TTo>())
ThrowHelper.ThrowInvalidTypeWithPointersNotSupported(typeof(TTo));

return new ReadOnlySpan<TTo>(
ref Unsafe.As<TFrom, TTo>(ref MemoryMarshal.GetReference(source)),
checked((int)((long)source.Length * Unsafe.SizeOf<TFrom>() / Unsafe.SizeOf<TTo>())));
}

/// <summary>
/// Creates a new readonly span over the portion of the target string.
/// </summary>
Expand Down
30 changes: 3 additions & 27 deletions src/System.Private.CoreLib/shared/System/Span.cs
Original file line number Diff line number Diff line change
Expand Up @@ -108,19 +108,6 @@ public unsafe Span(void* pointer, int length)
_length = length;
}

/// <summary>
/// Create a new span over a portion of a regular managed object. This can be useful
/// if part of a managed object represents a "fixed array." This is dangerous because neither the
/// <paramref name="length"/> is checked, nor <paramref name="obj"/> being null, nor the fact that
/// "rawPointer" actually lies within <paramref name="obj"/>.
/// </summary>
/// <param name="obj">The managed object that contains the data to span over.</param>
/// <param name="objectData">A reference to data within that object.</param>
/// <param name="length">The number of <typeparamref name="T"/> elements the memory contains.</param>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
[EditorBrowsable(EditorBrowsableState.Never)]
public static Span<T> DangerousCreate(object obj, ref T objectData, int length) => new Span<T>(ref objectData, length);

// Constructor for internal use only.
[MethodImpl(MethodImplOptions.AggressiveInlining)]
internal Span(ref T ptr, int length)
Expand All @@ -131,17 +118,6 @@ internal Span(ref T ptr, int length)
_length = length;
}

/// <summary>
/// Returns a reference to the 0th element of the Span. If the Span is empty, returns a reference to the location where the 0th element
/// would have been stored. Such a reference can be used for pinning but must never be dereferenced.
/// </summary>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
[EditorBrowsable(EditorBrowsableState.Never)]
internal ref T DangerousGetPinnableReference()
{
return ref _pointer.Value;
}

/// <summary>
/// The number of items in the span.
/// </summary>
Expand Down Expand Up @@ -232,7 +208,7 @@ public void Fill(T value)
if (length == 0)
return;

ref T r = ref DangerousGetPinnableReference();
ref T r = ref _pointer.Value;

// TODO: Create block fill for value types of power of two sizes e.g. 2,4,8,16

Expand Down Expand Up @@ -281,7 +257,7 @@ public void CopyTo(Span<T> destination)

if ((uint)_length <= (uint)destination.Length)
{
Buffer.Memmove(ref destination.DangerousGetPinnableReference(), ref _pointer.Value, (nuint)_length);
Buffer.Memmove(ref destination._pointer.Value, ref _pointer.Value, (nuint)_length);
}
else
{
Expand All @@ -302,7 +278,7 @@ public bool TryCopyTo(Span<T> destination)
bool retVal = false;
if ((uint)_length <= (uint)destination.Length)
{
Buffer.Memmove(ref destination.DangerousGetPinnableReference(), ref _pointer.Value, (nuint)_length);
Buffer.Memmove(ref destination._pointer.Value, ref _pointer.Value, (nuint)_length);
retVal = true;
}
return retVal;
Expand Down

0 comments on commit 497acea

Please sign in to comment.