Skip to content

Commit dd51b39

Browse files
marek-safarjkotas
andauthored
Make more suitable SPC instance methods static (dotnet#43280)
Co-authored-by: Jan Kotas <[email protected]>
1 parent 63c7fc6 commit dd51b39

21 files changed

+82
-88
lines changed

.editorconfig

+1
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,7 @@ csharp_space_between_square_brackets = false
159159

160160
# Analyzers
161161
dotnet_code_quality.ca1802.api_surface = private, internal
162+
dotnet_code_quality.ca1822.api_surface = private, internal
162163
dotnet_code_quality.ca2208.api_surface = public
163164

164165
# License header

src/coreclr/src/System.Private.CoreLib/src/System/Array.CoreCLR.cs

+2
Original file line numberDiff line numberDiff line change
@@ -483,6 +483,7 @@ private unsafe bool IsValueOfElementType(object value)
483483
public extern void Initialize();
484484
}
485485

486+
#pragma warning disable CA1822 // Mark members as static
486487
//----------------------------------------------------------------------------------------
487488
// ! READ THIS BEFORE YOU WORK ON THIS CLASS.
488489
//
@@ -619,4 +620,5 @@ private void RemoveAt<T>(int index)
619620
ThrowHelper.ThrowNotSupportedException(ExceptionResource.NotSupported_FixedSizeCollection);
620621
}
621622
}
623+
#pragma warning restore CA1822
622624
}

src/coreclr/src/System.Private.CoreLib/src/System/Diagnostics/StackFrame.CoreCLR.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,6 @@ private void BuildStackFrame(int skipFrames, bool needFileInfo)
4949
}
5050
}
5151

52-
private bool AppendStackFrameWithoutMethodBase(StringBuilder sb) => false;
52+
private static bool AppendStackFrameWithoutMethodBase(StringBuilder sb) => false;
5353
}
5454
}

src/coreclr/src/System.Private.CoreLib/src/System/MulticastDelegate.cs

+2-2
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@ private bool InvocationListEquals(MulticastDelegate d)
153153
return true;
154154
}
155155

156-
private bool TrySetSlot(object?[] a, int index, object o)
156+
private static bool TrySetSlot(object?[] a, int index, object o)
157157
{
158158
if (a[index] == null && System.Threading.Interlocked.CompareExchange<object?>(ref a[index], o, null) == null)
159159
return true;
@@ -322,7 +322,7 @@ private object[] DeleteFromInvocationList(object[] invocationList, int invocatio
322322
return newInvocationList;
323323
}
324324

325-
private bool EqualInvocationLists(object[] a, object[] b, int start, int count)
325+
private static bool EqualInvocationLists(object[] a, object[] b, int start, int count)
326326
{
327327
for (int i = 0; i < count; i++)
328328
{

src/coreclr/src/System.Private.CoreLib/src/System/Threading/Thread.CoreCLR.cs

+3-1
Original file line numberDiff line numberDiff line change
@@ -420,7 +420,7 @@ private bool TrySetApartmentStateUnchecked(ApartmentState state)
420420
[MethodImpl(MethodImplOptions.InternalCall)]
421421
internal extern int SetApartmentStateNative(int state);
422422
#else // FEATURE_COMINTEROP_APARTMENT_SUPPORT
423-
private bool TrySetApartmentStateUnchecked(ApartmentState state)
423+
private static bool TrySetApartmentStateUnchecked(ApartmentState state)
424424
{
425425
return state == ApartmentState.Unknown;
426426
}
@@ -503,10 +503,12 @@ public static int GetCurrentProcessorId()
503503
// we will record that in a readonly static so that it could become a JIT constant and bypass caching entirely.
504504
private static readonly bool s_isProcessorNumberReallyFast = ProcessorIdCache.ProcessorNumberSpeedCheck();
505505

506+
#pragma warning disable CA1822 // Mark members as static
506507
internal void ResetThreadPoolThread()
507508
{
508509
// Currently implemented in unmanaged method Thread::InternalReset and
509510
// called internally from the ThreadPool in NotifyWorkItemComplete.
510511
}
512+
#pragma warning restore CA1822
511513
} // End of class Thread
512514
}

src/coreclr/src/System.Private.CoreLib/src/System/Utf8String.CoreCLR.cs

+4
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,8 @@ public sealed partial class Utf8String
6363
[MethodImpl(MethodImplOptions.InternalCall)]
6464
public extern Utf8String(ReadOnlySpan<byte> value);
6565

66+
#pragma warning disable CA1822 // Mark members as static
67+
6668
#if !CORECLR
6769
static
6870
#endif
@@ -262,6 +264,8 @@ private Utf8String Ctor(string value)
262264
return Ctor(value.AsSpan());
263265
}
264266

267+
#pragma warning restore CA1822
268+
265269
/*
266270
* METHODS
267271
*/

src/libraries/System.Private.CoreLib/src/ILLink/ILLink.Suppressions.Shared.xml

+2-2
Original file line numberDiff line numberDiff line change
@@ -251,7 +251,7 @@
251251
<argument>ILLink</argument>
252252
<argument>IL2072</argument>
253253
<property name="Scope">member</property>
254-
<property name="Target">M:System.Diagnostics.Tracing.NullableTypeInfo.WriteData(System.Diagnostics.Tracing.TraceLoggingDataCollector,System.Diagnostics.Tracing.PropertyValue)</property>
254+
<property name="Target">M:System.Diagnostics.Tracing.NullableTypeInfo.WriteData(System.Diagnostics.Tracing.PropertyValue)</property>
255255
</attribute>
256256
<attribute fullname="System.Diagnostics.CodeAnalysis.UnconditionalSuppressMessageAttribute">
257257
<argument>ILLink</argument>
@@ -386,4 +386,4 @@
386386
<property name="Target">M:System.RuntimeType.ForwardCallToInvokeMember(System.String,System.Reflection.BindingFlags,System.Object,System.Object[],System.Boolean[],System.Int32[],System.Type[],System.Type)</property>
387387
</attribute>
388388
</assembly>
389-
</linker>
389+
</linker>

src/libraries/System.Private.CoreLib/src/System/ByReference.cs

+2
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ public ByReference(ref T value)
2525
throw new PlatformNotSupportedException();
2626
}
2727

28+
#pragma warning disable CA1822 // Mark members as static
2829
public ref T Value
2930
{
3031
// Implemented as a JIT intrinsic - This default implementation is for
@@ -33,5 +34,6 @@ public ref T Value
3334
[Intrinsic]
3435
get => throw new PlatformNotSupportedException();
3536
}
37+
#pragma warning restore CA1822
3638
}
3739
}

src/libraries/System.Private.CoreLib/src/System/Decimal.DecCalc.cs

+10-10
Original file line numberDiff line numberDiff line change
@@ -538,7 +538,7 @@ private static void IncreaseScale64(ref Buf12 bufNum, uint power)
538538
/// <returns>Returns new scale factor. bufRes updated in place, always 3 uints.</returns>
539539
private static unsafe int ScaleResult(Buf24* bufRes, uint hiRes, int scale)
540540
{
541-
Debug.Assert(hiRes < bufRes->Length);
541+
Debug.Assert(hiRes < Buf24.Length);
542542
uint* result = (uint*)bufRes;
543543

544544
// See if we need to scale the result. The combined scale must
@@ -666,7 +666,7 @@ private static unsafe int ScaleResult(Buf24* bufRes, uint hiRes, int scale)
666666
uint cur = 0;
667667
do
668668
{
669-
Debug.Assert(cur + 1 < bufRes->Length);
669+
Debug.Assert(cur + 1 < Buf24.Length);
670670
}
671671
while (++result[++cur] == 0);
672672

@@ -1007,7 +1007,7 @@ internal static unsafe void DecAddSub(ref DecCalc d1, ref DecCalc d2, bool sign)
10071007
uint* rgulNum = (uint*)&bufNum;
10081008
for (uint cur = 0; ;)
10091009
{
1010-
Debug.Assert(cur < bufNum.Length);
1010+
Debug.Assert(cur < Buf24.Length);
10111011
tmp64 += UInt32x32To64(rgulNum[cur], power);
10121012
rgulNum[cur] = (uint)tmp64;
10131013
cur++;
@@ -1019,7 +1019,7 @@ internal static unsafe void DecAddSub(ref DecCalc d1, ref DecCalc d2, bool sign)
10191019
if ((uint)tmp64 != 0)
10201020
{
10211021
// We're extending the result by another uint.
1022-
Debug.Assert(hiProd + 1 < bufNum.Length);
1022+
Debug.Assert(hiProd + 1 < Buf24.Length);
10231023
rgulNum[++hiProd] = (uint)tmp64;
10241024
}
10251025
}
@@ -1055,9 +1055,9 @@ internal static unsafe void DecAddSub(ref DecCalc d1, ref DecCalc d2, bool sign)
10551055
uint cur = 3;
10561056
do
10571057
{
1058-
Debug.Assert(cur < bufNum.Length);
1058+
Debug.Assert(cur < Buf24.Length);
10591059
} while (number[cur++]-- == 0);
1060-
Debug.Assert(hiProd < bufNum.Length);
1060+
Debug.Assert(hiProd < Buf24.Length);
10611061
if (number[hiProd] == 0 && --hiProd <= 2)
10621062
goto ReturnResult;
10631063
}
@@ -1082,7 +1082,7 @@ internal static unsafe void DecAddSub(ref DecCalc d1, ref DecCalc d2, bool sign)
10821082
uint* number = (uint*)&bufNum;
10831083
for (uint cur = 3; ++number[cur++] == 0;)
10841084
{
1085-
Debug.Assert(cur < bufNum.Length);
1085+
Debug.Assert(cur < Buf24.Length);
10861086
if (hiProd < cur)
10871087
{
10881088
number[cur] = 1;
@@ -2327,7 +2327,7 @@ private static unsafe void VarDecModFull(ref DecCalc d1, ref DecCalc d2, int sca
23272327
// The high bit of the dividend must not be set.
23282328
if (tmp64 > int.MaxValue)
23292329
{
2330-
Debug.Assert(high + 1 < b.Length);
2330+
Debug.Assert(high + 1 < Buf28.Length);
23312331
buf[++high] = (uint)(tmp64 >> 32);
23322332
}
23332333

@@ -2683,15 +2683,15 @@ public ulong High64
26832683
#endif
26842684
}
26852685

2686-
public int Length => 6;
2686+
public const int Length = 6;
26872687
}
26882688

26892689
private struct Buf28
26902690
{
26912691
public Buf24 Buf24;
26922692
public uint U6;
26932693

2694-
public int Length => 7;
2694+
public const int Length = 7;
26952695
}
26962696
}
26972697
}

src/libraries/System.Private.CoreLib/src/System/Diagnostics/Tracing/EventProvider.cs

+5-1
Original file line numberDiff line numberDiff line change
@@ -600,7 +600,11 @@ private static int IndexOfSessionInList(List<SessionInfo>? sessions, int etwSess
600600
/// returns an array of bytes representing the data, the index into that byte array where the data
601601
/// starts, and the command being issued associated with that data.
602602
/// </summary>
603-
private unsafe bool GetDataFromController(int etwSessionId,
603+
private
604+
#if !TARGET_WINDOWS
605+
static
606+
#endif
607+
unsafe bool GetDataFromController(int etwSessionId,
604608
Interop.Advapi32.EVENT_FILTER_DESCRIPTOR* filterData, out ControllerCommand command, out byte[]? data, out int dataStart)
605609
{
606610
data = null;

src/libraries/System.Private.CoreLib/src/System/Diagnostics/Tracing/TraceLogging/ArrayTypeInfo.cs

+4-4
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,9 @@ public override void WriteMetadata(
3232
collector.EndBufferedArray();
3333
}
3434

35-
public override void WriteData(TraceLoggingDataCollector collector, PropertyValue value)
35+
public override void WriteData(PropertyValue value)
3636
{
37-
int bookmark = collector.BeginBufferedArray();
37+
int bookmark = TraceLoggingDataCollector.BeginBufferedArray();
3838

3939
int count = 0;
4040
Array? array = (Array?)value.ReferenceValue;
@@ -43,11 +43,11 @@ public override void WriteData(TraceLoggingDataCollector collector, PropertyValu
4343
count = array.Length;
4444
for (int i = 0; i < array.Length; i++)
4545
{
46-
this.elementInfo.WriteData(collector, elementInfo.PropertyValueFactory(array.GetValue(i)));
46+
this.elementInfo.WriteData(elementInfo.PropertyValueFactory(array.GetValue(i)));
4747
}
4848
}
4949

50-
collector.EndBufferedArray(bookmark, count);
50+
TraceLoggingDataCollector.EndBufferedArray(bookmark, count);
5151
}
5252

5353
public override object? GetData(object? value)

src/libraries/System.Private.CoreLib/src/System/Diagnostics/Tracing/TraceLogging/EnumerableTypeInfo.cs

+4-4
Original file line numberDiff line numberDiff line change
@@ -36,22 +36,22 @@ public override void WriteMetadata(
3636
collector.EndBufferedArray();
3737
}
3838

39-
public override void WriteData(TraceLoggingDataCollector collector, PropertyValue value)
39+
public override void WriteData(PropertyValue value)
4040
{
41-
int bookmark = collector.BeginBufferedArray();
41+
int bookmark = TraceLoggingDataCollector.BeginBufferedArray();
4242

4343
int count = 0;
4444
IEnumerable? enumerable = (IEnumerable?)value.ReferenceValue;
4545
if (enumerable != null)
4646
{
4747
foreach (object? element in enumerable)
4848
{
49-
this.elementInfo.WriteData(collector, elementInfo.PropertyValueFactory(element));
49+
this.elementInfo.WriteData(elementInfo.PropertyValueFactory(element));
5050
count++;
5151
}
5252
}
5353

54-
collector.EndBufferedArray(bookmark, count);
54+
TraceLoggingDataCollector.EndBufferedArray(bookmark, count);
5555
}
5656

5757
public override object? GetData(object? value)

src/libraries/System.Private.CoreLib/src/System/Diagnostics/Tracing/TraceLogging/InvokeTypeInfo.cs

+2-2
Original file line numberDiff line numberDiff line change
@@ -62,13 +62,13 @@ public override void WriteMetadata(
6262
}
6363
}
6464

65-
public override void WriteData(TraceLoggingDataCollector collector, PropertyValue value)
65+
public override void WriteData(PropertyValue value)
6666
{
6767
if (this.properties != null)
6868
{
6969
foreach (PropertyAnalysis property in this.properties)
7070
{
71-
property.typeInfo.WriteData(collector, property.getter(value));
71+
property.typeInfo.WriteData(property.getter(value));
7272
}
7373
}
7474
}

src/libraries/System.Private.CoreLib/src/System/Diagnostics/Tracing/TraceLogging/PropertyValue.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -205,7 +205,7 @@ private abstract class TypeHelper
205205
{
206206
public abstract Func<PropertyValue, PropertyValue> GetPropertyGetter(PropertyInfo property);
207207

208-
protected Delegate GetGetMethod(PropertyInfo property, Type propertyType)
208+
protected static Delegate GetGetMethod(PropertyInfo property, Type propertyType)
209209
{
210210
return property.GetMethod!.CreateDelegate(typeof(Func<,>).MakeGenericType(property.DeclaringType!, propertyType));
211211
}

0 commit comments

Comments
 (0)