blob: 0fe7eb4686fd2db154770def52372edb412da8c7 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
|
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
namespace Internal.TypeSystem
{
// Functionality related to deterministic ordering of types
partial class InstantiatedMethod
{
protected internal override int ClassCode => -873941872;
protected internal override int CompareToImpl(MethodDesc other, TypeSystemComparer comparer)
{
var otherMethod = (InstantiatedMethod)other;
// Sort by instantiation before sorting by associated method definition
// The goal of this is to keep methods which work with the same types near
// to each other. This is a better heuristic than sorting by method definition
// then by instantiation.
//
// The goal is to sort methods like SomeClass.SomeMethod<UserStruct>,
// near SomeOtherClass.SomeOtherMethod<UserStruct, int>
int result = 0;
// Sort instantiations of the same type together
for (int i = 0; i < _instantiation.Length; i++)
{
if (i >= otherMethod._instantiation.Length)
return 1;
result = comparer.Compare(_instantiation[i], otherMethod._instantiation[i]);
if (result != 0)
return result;
}
if (_instantiation.Length < otherMethod._instantiation.Length)
return -1;
result = comparer.Compare(_methodDef, otherMethod._methodDef);
return result;
}
}
}
|