Skip to content

Commit 385a0c6

Browse files
authored
[mono] Turn methods with no instance access to static (#43228)
* [mono] Turn methods with no instance access to static * Review feedback
1 parent a4b566a commit 385a0c6

21 files changed

+34
-146
lines changed

src/mono/netcore/System.Private.CoreLib/System.Private.CoreLib.csproj

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -238,7 +238,6 @@
238238
<Compile Include="$(BclSourcesRoot)\System\Runtime\CompilerServices\JitHelpers.cs" />
239239
<Compile Include="$(BclSourcesRoot)\System\Runtime\CompilerServices\RuntimeHelpers.Mono.cs" />
240240
<Compile Include="$(BclSourcesRoot)\System\Runtime\CompilerServices\RuntimeFeature.Mono.cs" />
241-
<Compile Include="$(BclSourcesRoot)\System\Runtime\InteropServices\CriticalHandle.Mono.cs" />
242241
<Compile Include="$(BclSourcesRoot)\System\Runtime\InteropServices\GCHandle.Mono.cs" />
243242
<Compile Include="$(BclSourcesRoot)\System\Runtime\InteropServices\Marshal.Mono.cs" />
244243
<Compile Include="$(BclSourcesRoot)\System\Runtime\InteropServices\MemoryMarshal.Mono.cs" />

src/mono/netcore/System.Private.CoreLib/src/System/Array.Mono.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -534,6 +534,7 @@ private void SetGenericValueImpl<T>(int pos, ref T value)
534534
[MethodImplAttribute(MethodImplOptions.InternalCall)]
535535
private extern void SetValueRelaxedImpl(object? value, int pos);
536536

537+
#pragma warning disable CA1822
537538
/*
538539
* These methods are used to implement the implicit generic interfaces
539540
* implemented by arrays in NET 2.0.
@@ -637,5 +638,6 @@ internal void InternalArray__set_Item<T>(int index, T item)
637638
// Do not change this to call SetGenericValue_icall directly, due to special casing in the runtime.
638639
SetGenericValueImpl(index, ref item);
639640
}
641+
#pragma warning restore CA1822
640642
}
641643
}

src/mono/netcore/System.Private.CoreLib/src/System/Diagnostics/StackFrame.Mono.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ private void BuildStackFrame(int skipFrames, bool needFileInfo)
4545
}
4646
}
4747

48-
private bool AppendStackFrameWithoutMethodBase(StringBuilder sb) => false;
48+
private static bool AppendStackFrameWithoutMethodBase(StringBuilder sb) => false;
4949

5050
[MethodImplAttribute(MethodImplOptions.InternalCall)]
5151
private static extern bool get_frame_info(int skipFrames, bool needFileInfo,

src/mono/netcore/System.Private.CoreLib/src/System/MulticastDelegate.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,7 @@ protected sealed override Delegate CombineImpl(Delegate? follow)
167167
}
168168

169169
/* Based on the Boyer-Moore string search algorithm */
170-
private int LastIndexOf(Delegate[] haystack, Delegate[] needle)
170+
private static int LastIndexOf(Delegate[] haystack, Delegate[] needle)
171171
{
172172
if (haystack.Length < needle.Length)
173173
return -1;

src/mono/netcore/System.Private.CoreLib/src/System/Reflection/Emit/AssemblyBuilder.Mono.cs

Lines changed: 2 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -419,61 +419,14 @@ public void SetCustomAttribute(ConstructorInfo con, byte[] binaryAttribute)
419419
SetCustomAttribute(new CustomAttributeBuilder(con, binaryAttribute));
420420
}
421421

422-
private Exception not_supported()
422+
private static Exception not_supported()
423423
{
424424
// Strange message but this is what MS.NET prints...
425425
return new NotSupportedException("The invoked member is not supported in a dynamic module.");
426426
}
427427

428-
private string create_assembly_version(string version)
429-
{
430-
string[] parts = version.Split('.');
431-
int[] ver = new int[4] { 0, 0, 0, 0 };
432-
433-
if ((parts.Length < 0) || (parts.Length > 4))
434-
throw new ArgumentException("The version specified '" + version + "' is invalid");
435-
436-
for (int i = 0; i < parts.Length; ++i)
437-
{
438-
if (parts[i] == "*")
439-
{
440-
DateTime now = DateTime.Now;
441-
442-
if (i == 2)
443-
{
444-
ver[2] = (now - new DateTime(2000, 1, 1)).Days;
445-
if (parts.Length == 3)
446-
ver[3] = (now.Second + (now.Minute * 60) + (now.Hour * 3600)) / 2;
447-
}
448-
else
449-
if (i == 3)
450-
ver[3] = (now.Second + (now.Minute * 60) + (now.Hour * 3600)) / 2;
451-
else
452-
throw new ArgumentException("The version specified '" + version + "' is invalid");
453-
}
454-
else
455-
{
456-
try
457-
{
458-
ver[i] = int.Parse(parts[i]);
459-
}
460-
catch (FormatException)
461-
{
462-
throw new ArgumentException("The version specified '" + version + "' is invalid");
463-
}
464-
}
465-
}
466-
467-
return ver[0] + "." + ver[1] + "." + ver[2] + "." + ver[3];
468-
}
469-
470-
private string GetCultureString(string str)
471-
{
472-
return (str == "neutral" ? string.Empty : str);
473-
}
474-
475428
/*Warning, @typeArguments must be a mscorlib internal array. So make a copy before passing it in*/
476-
internal Type MakeGenericType(Type gtd, Type[] typeArguments)
429+
internal static Type MakeGenericType(Type gtd, Type[] typeArguments)
477430
{
478431
return new TypeBuilderInstantiation(gtd, typeArguments);
479432
}

src/mono/netcore/System.Private.CoreLib/src/System/Reflection/Emit/ConstructorBuilder.Mono.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -387,17 +387,17 @@ private void RejectIfCreated()
387387
throw new InvalidOperationException("Type definition of the method is complete.");
388388
}
389389

390-
private Exception not_supported()
390+
private static Exception not_supported()
391391
{
392392
return new NotSupportedException("The invoked member is not supported in a dynamic module.");
393393
}
394394

395-
private Exception not_after_created()
395+
private static Exception not_after_created()
396396
{
397397
return new InvalidOperationException("Unable to change after type has been created.");
398398
}
399399

400-
private Exception not_created()
400+
private static Exception not_created()
401401
{
402402
return new NotSupportedException("The type is not yet created.");
403403
}

src/mono/netcore/System.Private.CoreLib/src/System/Reflection/Emit/CustomAttributeBuilder.Mono.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ public CustomAttributeBuilder(ConstructorInfo con, object?[] constructorArgs,
112112
Initialize(con, constructorArgs, namedProperties, propertyValues, namedFields, fieldValues);
113113
}
114114

115-
private bool IsValidType(Type t)
115+
private static bool IsValidType(Type t)
116116
{
117117
/* FIXME: Add more checks */
118118
if (t.IsArray && t.GetArrayRank() > 1)
@@ -130,7 +130,7 @@ private bool IsValidType(Type t)
130130
return true;
131131
}
132132

133-
private bool IsValidParam(object o, Type paramType)
133+
private static bool IsValidParam(object o, Type paramType)
134134
{
135135
Type t = o.GetType();
136136
if (!IsValidType(t))

src/mono/netcore/System.Private.CoreLib/src/System/Reflection/Emit/FieldBuilder.Mono.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -234,7 +234,7 @@ public override void SetValue(object? obj, object? val, BindingFlags invokeAttr,
234234
throw CreateNotSupportedException();
235235
}
236236

237-
private Exception CreateNotSupportedException()
237+
private static Exception CreateNotSupportedException()
238238
{
239239
return new NotSupportedException("The invoked member is not supported in a dynamic module.");
240240
}

src/mono/netcore/System.Private.CoreLib/src/System/Reflection/Emit/GenericTypeParameterBuilder.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -450,7 +450,7 @@ public void SetCustomAttribute(ConstructorInfo con, byte[] binaryAttribute)
450450
SetCustomAttribute(new CustomAttributeBuilder(con, binaryAttribute));
451451
}
452452

453-
private Exception not_supported()
453+
private static Exception not_supported()
454454
{
455455
return new NotSupportedException();
456456
}

src/mono/netcore/System.Private.CoreLib/src/System/Reflection/Emit/ILGenerator.Mono.cs

Lines changed: 1 addition & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -57,18 +57,8 @@ internal struct ILExceptionBlock
5757
internal int len;
5858
internal int filter_offset;
5959
#endregion
60-
61-
internal void Debug()
62-
{
63-
#if FALSE
64-
System.Console.Write ("\ttype="+type.ToString()+" start="+start.ToString()+" len="+len.ToString());
65-
if (extype != null)
66-
System.Console.WriteLine (" extype="+extype.ToString());
67-
else
68-
System.Console.WriteLine (String.Empty);
69-
#endif
70-
}
7160
}
61+
7262
internal struct ILExceptionInfo
7363
{
7464
#region Sync with MonoILExceptionInfo in object-internals.h
@@ -153,15 +143,6 @@ internal void PatchFilterClause(int start)
153143
}
154144
}
155145

156-
internal void Debug(int b)
157-
{
158-
#if FALSE
159-
System.Console.WriteLine ("Handler {0} at {1}, len: {2}", b, start, len);
160-
for (int i = 0; i < handlers.Length; ++i)
161-
handlers [i].Debug ();
162-
#endif
163-
}
164-
165146
private void add_block(int offset)
166147
{
167148
if (handlers != null)
@@ -947,13 +928,9 @@ public virtual void EndExceptionBlock()
947928
InternalEndClause();
948929
MarkLabel(ex_handlers[cur_block].end);
949930
ex_handlers[cur_block].End(code_len);
950-
ex_handlers[cur_block].Debug(cur_block);
951-
//System.Console.WriteLine ("End Block {0} (handlers: {1})", cur_block, ex_handlers [cur_block].NumHandlers ());
952931
open_blocks.Pop();
953932
if (open_blocks.Count > 0)
954933
cur_block = (int)open_blocks.Peek()!;
955-
//Console.WriteLine ("curblock restored to {0}", cur_block);
956-
//throw new NotImplementedException ();
957934
}
958935

959936
public virtual void EndScope()

0 commit comments

Comments
 (0)