Welcome to mirror list, hosted at ThFree Co, Russian Federation.

InstantiatedType.Sorting.cs « Sorting « TypeSystem « Common « tools « coreclr « src - github.com/dotnet/runtime.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 887effee9706db7cb21e60a791acec155fe4ed16 (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
39
40
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

using Debug = System.Diagnostics.Debug;

namespace Internal.TypeSystem
{
    // Functionality related to deterministic ordering of types
    partial class InstantiatedType
    {
        protected internal override int ClassCode => 1150020412;

        protected internal override int CompareToImpl(TypeDesc other, TypeSystemComparer comparer)
        {
            var otherType = (InstantiatedType)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 classes like SomeClass<UserStruct>,
            // near SomeOtherClass<UserStruct, int>

            int result = 0;
            // Sort instantiations of the same type together
            for (int i = 0; i < _instantiation.Length; i++)
            {
                if (i >= otherType._instantiation.Length)
                    return 1;
                result = comparer.Compare(_instantiation[i], otherType._instantiation[i]);
                if (result != 0)
                    return result;
            }
            if (_instantiation.Length < otherType._instantiation.Length)
                return -1;

            return comparer.Compare(_typeDef, otherType._typeDef);
        }
    }
}