Skip to content

Commit 21306e8

Browse files
thaystgliveans
authored andcommitted
[mono] Simplify of OffsetToStringData as it's done on coreclr (dotnet#93987)
* Change implementation of OffsetToStringData as it's done on coreclr * Fix comment * Remove more comments * completely remove the comments * Update RuntimeHelpers.Mono.cs * Addressing comments * Addressing @lambdageek comment.
1 parent a6ff336 commit 21306e8

File tree

4 files changed

+9
-19
lines changed

4 files changed

+9
-19
lines changed

src/mono/System.Private.CoreLib/src/System/Runtime/CompilerServices/RuntimeHelpers.Mono.cs

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -30,11 +30,7 @@ public static void InitializeArray(Array array, RuntimeFieldHandle fldHandle)
3030
}
3131

3232
[Obsolete("OffsetToStringData has been deprecated. Use string.GetPinnableReference() instead.")]
33-
public static int OffsetToStringData
34-
{
35-
[Intrinsic]
36-
get => OffsetToStringData;
37-
}
33+
public static int OffsetToStringData => string.OFFSET_TO_STRING;
3834

3935
[MethodImplAttribute(MethodImplOptions.InternalCall)]
4036
private static extern int InternalGetHashCode(object? o);

src/mono/System.Private.CoreLib/src/System/String.Mono.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,12 @@ public static string IsInterned(string str)
3030
[MethodImplAttribute(MethodImplOptions.InternalCall)]
3131
private static extern string InternalIntern(string str);
3232

33+
#if TARGET_64BIT
34+
internal const int OFFSET_TO_STRING = 20;
35+
#else
36+
internal const int OFFSET_TO_STRING = 12;
37+
#endif
38+
3339
// TODO: Should be pointing to Buffer instead
3440
#region Runtime method-to-ir dependencies
3541

src/mono/mono/mini/interp/transform.c

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2305,16 +2305,7 @@ interp_handle_intrinsics (TransformData *td, MonoMethod *target_method, MonoClas
23052305
*op = MINT_INITBLK;
23062306
}
23072307
} else if (in_corlib && !strcmp (klass_name_space, "System.Runtime.CompilerServices") && !strcmp (klass_name, "RuntimeHelpers")) {
2308-
if (!strcmp (tm, "get_OffsetToStringData")) {
2309-
g_assert (csignature->param_count == 0);
2310-
int offset = MONO_STRUCT_OFFSET (MonoString, chars);
2311-
interp_add_ins (td, MINT_LDC_I4);
2312-
WRITE32_INS (td->last_ins, 0, &offset);
2313-
push_simple_type (td, STACK_TYPE_I4);
2314-
interp_ins_set_dreg (td->last_ins, td->sp [-1].local);
2315-
td->ip += 5;
2316-
return TRUE;
2317-
} else if (!strcmp (tm, "GetHashCode") || !strcmp (tm, "InternalGetHashCode")) {
2308+
if (!strcmp (tm, "GetHashCode") || !strcmp (tm, "InternalGetHashCode")) {
23182309
*op = MINT_INTRINS_GET_HASHCODE;
23192310
} else if (!strcmp (tm, "TryGetHashCode")) {
23202311
*op = MINT_INTRINS_TRY_GET_HASHCODE;

src/mono/mono/mini/intrinsics.c

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -935,10 +935,7 @@ mini_emit_inst_for_method (MonoCompile *cfg, MonoMethod *cmethod, MonoMethodSign
935935
} else
936936
return NULL;
937937
} else if (cmethod->klass == runtime_helpers_class) {
938-
if (strcmp (cmethod->name, "get_OffsetToStringData") == 0 && fsig->param_count == 0) {
939-
EMIT_NEW_ICONST (cfg, ins, MONO_STRUCT_OFFSET (MonoString, chars));
940-
return ins;
941-
} else if (!strcmp (cmethod->name, "GetRawData")) {
938+
if (!strcmp (cmethod->name, "GetRawData")) {
942939
int dreg = alloc_preg (cfg);
943940
EMIT_NEW_BIALU_IMM (cfg, ins, OP_PADD_IMM, dreg, args [0]->dreg, MONO_ABI_SIZEOF (MonoObject));
944941
return ins;

0 commit comments

Comments
 (0)