-
Notifications
You must be signed in to change notification settings - Fork 5.1k
Obsolete RuntimeHelpers.OffsetToStringData #35722
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9093,6 +9093,7 @@ public static partial class RuntimeFeature | |
} | ||
public static partial class RuntimeHelpers | ||
{ | ||
[System.ObsoleteAttribute("OffsetToStringData is obsolete. Use string.GetPinnableReference() instead.")] | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should we be following @terrajobst's new plan for obsoletion? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It's a good question. :) |
||
public static int OffsetToStringData { get { throw null; } } | ||
public static IntPtr AllocateTypeAssociatedMemory(Type type, int size) { throw null; } | ||
public static void EnsureSufficientExecutionStack() { } | ||
|
Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -70,22 +70,6 @@ public static unsafe void GetObjectValue() | |||||||||||||||||||||||||||||||||||||||||||||||||||
Assert.Equal(i, (int)iOV); | ||||||||||||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||
[Fact] | ||||||||||||||||||||||||||||||||||||||||||||||||||||
public static unsafe void OffsetToStringData() | ||||||||||||||||||||||||||||||||||||||||||||||||||||
{ | ||||||||||||||||||||||||||||||||||||||||||||||||||||
// RuntimeHelpers.OffsetToStringData | ||||||||||||||||||||||||||||||||||||||||||||||||||||
char[] expectedValues = new char[] { 'a', 'b', 'c', 'd', 'e', 'f' }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
string s = "abcdef"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||
fixed (char* values = s) // Compiler will use OffsetToStringData with fixed statements | ||||||||||||||||||||||||||||||||||||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The runtime/src/libraries/System.Runtime/tests/System/StringTests.cs Lines 871 to 895 in 61733e2
|
||||||||||||||||||||||||||||||||||||||||||||||||||||
{ | ||||||||||||||||||||||||||||||||||||||||||||||||||||
for (int i = 0; i < expectedValues.Length; i++) | ||||||||||||||||||||||||||||||||||||||||||||||||||||
{ | ||||||||||||||||||||||||||||||||||||||||||||||||||||
Assert.Equal(expectedValues[i], values[i]); | ||||||||||||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||
[Fact] | ||||||||||||||||||||||||||||||||||||||||||||||||||||
public static void InitializeArray() | ||||||||||||||||||||||||||||||||||||||||||||||||||||
{ | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
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.
Would there be a downside to moving this conv_u to below lCommonExit? Then the duplicate one in the other branch could be removed.
Uh oh!
There was an error while loading. Please reload this page.
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 guess maybe it's better for the same type to be on the stack prior to the branching?
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.
Yeah, the stack should be the same at all possible entry points to the branch. In one case the stack will have an i4, and in the other case the stack will have a char&. I was concerned that this would break things.
The codegen pattern here is identical to the codegen pattern Roslyn emits for pattern fixed statements. See Sharplab. Honestly I think some minor optimizations are possible, but I was nervous about straying from what the compiler itself already implements.