Repository: dotnet/runtime
File: src/coreclr/vm/methodtablebuilder.cpp (C++)

Code before:
    //
    // Run through the method list and calculate the following:
    // # methods.
    // # "other" methods (i.e. static or private)
    // # non-other methods
    //

    HENUMInternalHolder hEnumMethod(pMDInternalImport);
    hr = hEnumMethod.EnumInitNoThrow(mdtMethodDef, GetCl());
    if (FAILED(hr))
    {
        BuildMethodTableThrowException(hr, *bmtError);
    }

    // Allocate an array to contain the method tokens as well as information about the methods.
    DWORD cMethAndGaps = hEnumMethod.EnumGetCount();

    if ((DWORD)MAX_SLOT_INDEX <= cMethAndGaps)
        BuildMethodTableThrowException(IDS_CLASSLOAD_TOO_MANY_METHODS);

    // In a worst case the number of declared methods can double
    // as each async method may have two variants.
    // The method count is typically a modest number though.
    // We will reserve twice the size for the builder, up to the max, just in case.
    DWORD cMethUpperBound = cMethAndGaps * 2;
    if (cMethUpperBound >= (DWORD)MAX_SLOT_INDEX)
    {
        cMethUpperBound = MAX_SLOT_INDEX - 1;
    }

    bmtMethod->m_cMaxDeclaredMethods = (SLOT_INDEX)cMethUpperBound;
    bmtMethod->m_cDeclaredMethods = 0;
    bmtMethod->m_rgDeclaredMethods = new (GetStackingAllocator())
        bmtMDMethod *[bmtMethod->m_cMaxDeclaredMethods];

    enum { SeenCtor = 1, SeenInvoke = 2, SeenBeginInvoke = 4, SeenEndInvoke = 8};
    unsigned delegateMethodsSeen = 0;

    for (i = 0; i < cMethAndGaps; i++)
    {
        ULONG dwMethodRVA;
        DWORD dwImplFlags;
        MethodClassification type;
        METHOD_IMPL_TYPE implType;
        LPSTR strMethodName;

        pMemberSignature = NULL;
        cMemberSignature = 0;

        //
        // Go to the next method and retrieve its attributes.

Review comment (suggestion):
```suggestion
    if ((DWORD)MAX_SLOT_INDEX <= cMethUpperBound)
```
So that it is same style as ` if ((DWORD)MAX_SLOT_INDEX <= cMethAndGaps)`  a few lines above

Code after:
    //
    // Run through the method list and calculate the following:
    // # methods.
    // # "other" methods (i.e. static or private)
    // # non-other methods
    //

    HENUMInternalHolder hEnumMethod(pMDInternalImport);
    hr = hEnumMethod.EnumInitNoThrow(mdtMethodDef, GetCl());
    if (FAILED(hr))
    {
        BuildMethodTableThrowException(hr, *bmtError);
    }

    // Allocate an array to contain the method tokens as well as information about the methods.
    DWORD cMethAndGaps = hEnumMethod.EnumGetCount();

    if ((DWORD)MAX_SLOT_INDEX <= cMethAndGaps)
        BuildMethodTableThrowException(IDS_CLASSLOAD_TOO_MANY_METHODS);

    // In a worst case the number of declared methods can double
    // as each async method may have two variants.
    // The method count is typically a modest number though.
    // We will reserve twice the size for the builder, up to the max, just in case.
    DWORD cMethUpperBound = cMethAndGaps * 2;
    if ((DWORD)MAX_SLOT_INDEX <= cMethUpperBound)
    {
        cMethUpperBound = MAX_SLOT_INDEX - 1;
    }

    bmtMethod->m_cMaxDeclaredMethods = (SLOT_INDEX)cMethUpperBound;
    bmtMethod->m_cDeclaredMethods = 0;
    bmtMethod->m_rgDeclaredMethods = new (GetStackingAllocator())
        bmtMDMethod *[bmtMethod->m_cMaxDeclaredMethods];

    enum { SeenCtor = 1, SeenInvoke = 2, SeenBeginInvoke = 4, SeenEndInvoke = 8};
    unsigned delegateMethodsSeen = 0;

    for (i = 0; i < cMethAndGaps; i++)
    {
        ULONG dwMethodRVA;
        DWORD dwImplFlags;
        MethodClassification type;
        METHOD_IMPL_TYPE implType;
        LPSTR strMethodName;

        pMemberSignature = NULL;
        cMemberSignature = 0;

        //
        // Go to the next method and retrieve its attributes.