This repository has been archived by the owner on Jan 23, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2.7k
[WIP] Don't Merge MemoryMarshal #14833
Closed
Closed
Changes from 1 commit
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
31 changes: 31 additions & 0 deletions
31
src/mscorlib/src/System/Runtime/InteropServices/MemoryMarshal.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
// Licensed to the .NET Foundation under one or more agreements. | ||
// The .NET Foundation licenses this file to you under the MIT license. | ||
// See the LICENSE file in the project root for more information. | ||
|
||
namespace src.System.Runtime.InteropServices | ||
{ | ||
using System; | ||
using System.Runtime.CompilerServices; | ||
|
||
public static class MemoryMarshal | ||
{ | ||
/// <summary> | ||
/// Creates a span over the range specified. However this does no bounds checking therefore is dangerous | ||
/// all validation should be done prior to calling this method | ||
/// </summary> | ||
/// <param name="array">The target array.</param> | ||
/// <param name="start">The index at which to begin the span.</param> | ||
/// <param name="length">The number of items in the span.</param> | ||
[MethodImpl(MethodImplOptions.AggressiveInlining)] | ||
public static Span<T> DangerousCreateSpan<T>(T[] array, int start, int length) => new Span<T>(ref Unsafe.Add(ref Unsafe.As<byte, T>(ref array.GetRawSzArrayData()), start), length); | ||
|
||
/// <summary> | ||
/// Creates a memory instance over the range. However this does no bounds checking therefore is dangerous | ||
/// </summary> | ||
/// <param name="array">The target array.</param> | ||
/// <param name="start">The index at which to begin the span.</param> | ||
/// <param name="length">The number of items in the span.</param> | ||
[MethodImpl(MethodImplOptions.AggressiveInlining)] | ||
public static Memory<T> DangerousCreateMemory<T>(T[] array, int start, int length) => new Memory<T>(start, length, array); | ||
} | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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 approved APIs do not have Dangerous in names...
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.
I forgot that got removed.
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.
Actually, I do not see APIs like these in the approved list. Where did these exact APIs got approved?
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.
https://github.com/dotnet/corefx/issues/24296
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.
Basically there are two API Reviewed Issues that have been approved that converge on this single type.
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.
Ok, I have not noticed this API review. I do not think that the approved APIs are good.
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.
Okay, I will hold off until that discussion has been had over there.