# Global Metrics

path: .metrics.mi.mi_original
old: -1.518874627876258
new: 37.50542887441638
path: .metrics.mi.mi_sei
old: -45.16866173089804
new: 10.819539330213363
path: .metrics.mi.mi_visual_studio
old: 0.0
new: 21.932999341763963
path: .metrics.nargs.average
old: 2.533333333333333
new: 5.0
path: .metrics.nargs.sum
old: 38.0
new: 5.0
path: .metrics.cognitive.sum
old: 139.0
new: 31.0
path: .metrics.cognitive.average
old: 9.266666666666667
new: 31.0
path: .metrics.nexits.sum
old: 7.0
new: 2.0
path: .metrics.nexits.average
old: 0.4666666666666667
new: 2.0
path: .metrics.nom.total
old: 15.0
new: 1.0
path: .metrics.nom.functions
old: 15.0
new: 1.0
path: .metrics.halstead.difficulty
old: 121.79292929292929
new: 27.36936936936937
path: .metrics.halstead.bugs
old: 6.85937282642284
new: 0.7620335843437133
path: .metrics.halstead.time
old: 163997.03261589157
new: 6072.54224783883
path: .metrics.halstead.n2
old: 198.0
new: 111.0
path: .metrics.halstead.estimated_program_length
old: 1690.1375163688365
new: 888.7860989824748
path: .metrics.halstead.purity_ratio
old: 0.5483898495680846
new: 1.584288946492825
path: .metrics.halstead.volume
old: 24237.42169782449
new: 3993.725941797888
path: .metrics.halstead.vocabulary
old: 233.0
new: 139.0
path: .metrics.halstead.N1
old: 1704.0
new: 344.0
path: .metrics.halstead.N2
old: 1378.0
new: 217.0
path: .metrics.halstead.length
old: 3082.0
new: 561.0
path: .metrics.halstead.effort
old: 2951946.5870860484
new: 109305.76046109894
path: .metrics.halstead.n1
old: 35.0
new: 28.0
path: .metrics.halstead.level
old: 0.008210657267261041
new: 0.03653719552337064
path: .metrics.loc.sloc
old: 561.0
new: 183.0
path: .metrics.loc.cloc
old: 64.0
new: 31.0
path: .metrics.loc.blank
old: 79.0
new: 43.0
path: .metrics.loc.lloc
old: 186.0
new: 66.0
path: .metrics.loc.ploc
old: 418.0
new: 109.0
path: .metrics.cyclomatic.sum
old: 76.0
new: 26.0
path: .metrics.cyclomatic.average
old: 4.75
new: 13.0

# Spaces Data

## Minimal test - lines (32, 121)

path: .spaces[0].metrics.halstead.N1
old: 14.0
new: 333.0
path: .spaces[0].metrics.halstead.bugs
old: 0.0246943551168509
new: 0.7795052983163099
path: .spaces[0].metrics.halstead.effort
old: 637.6442032350528
new: 113086.42872557355
path: .spaces[0].metrics.halstead.purity_ratio
old: 1.945530556036326
new: 1.1672013494580653
path: .spaces[0].metrics.halstead.vocabulary
old: 17.0
new: 102.0
path: .spaces[0].metrics.halstead.difficulty
old: 5.777777777777778
new: 33.2972972972973
path: .spaces[0].metrics.halstead.length
old: 27.0
new: 509.0
path: .spaces[0].metrics.halstead.n2
old: 9.0
new: 74.0
path: .spaces[0].metrics.halstead.volume
old: 110.36149671375917
new: 3396.2644990634913
path: .spaces[0].metrics.halstead.estimated_program_length
old: 52.529325012980806
new: 594.1054868741552
path: .spaces[0].metrics.halstead.N2
old: 13.0
new: 176.0
path: .spaces[0].metrics.halstead.time
old: 35.42467795750294
new: 6282.579373642975
path: .spaces[0].metrics.halstead.level
old: 0.17307692307692307
new: 0.030032467532467532
path: .spaces[0].metrics.halstead.n1
old: 8.0
new: 28.0
path: .spaces[0].metrics.cognitive.sum
old: 0.0
new: 31.0
path: .spaces[0].metrics.cognitive.average
old: 0.0
new: 31.0
path: .spaces[0].metrics.nargs.average
old: 2.0
new: 5.0
path: .spaces[0].metrics.nargs.sum
old: 2.0
new: 5.0
path: .spaces[0].metrics.cyclomatic.average
old: 1.0
new: 25.0
path: .spaces[0].metrics.cyclomatic.sum
old: 1.0
new: 25.0
path: .spaces[0].metrics.mi.mi_original
old: 120.23754699949156
new: 50.07483990532313
path: .spaces[0].metrics.mi.mi_visual_studio
old: 70.3143549704629
new: 29.2835321083761
path: .spaces[0].metrics.mi.mi_sei
old: 97.86708065221184
new: 16.941762100315728
path: .spaces[0].metrics.loc.lloc
old: 1.0
new: 65.0
path: .spaces[0].metrics.loc.sloc
old: 5.0
new: 90.0
path: .spaces[0].metrics.loc.blank
old: 1.0
new: 12.0
path: .spaces[0].metrics.loc.cloc
old: 0.0
new: 5.0
path: .spaces[0].metrics.loc.ploc
old: 4.0
new: 73.0
path: .spaces[0].metrics.nexits.average
old: 1.0
new: 2.0
path: .spaces[0].metrics.nexits.sum
old: 1.0
new: 2.0

### Code

    PrepareAndDispatch(nsXPTCStubBase * self, uint32_t methodIndex,
                       uint64_t * args, uint64_t * gpregs, double *fpregs)
    {
        nsXPTCMiniVariant paramBuffer[PARAM_BUFFER_COUNT];
        const nsXPTMethodInfo* info;
        uint32_t paramCount;
        uint32_t i;

        NS_ASSERTION(self,"no self");

        self->mEntry->GetMethodInfo(uint16_t(methodIndex), &info);
        NS_ASSERTION(info,"no method info");
        if (!info)
            return NS_ERROR_UNEXPECTED;

        paramCount = info->GetParamCount();

        const uint8_t indexOfJSContext = info->IndexOfJSContext();

        uint64_t* ap = args;
        uint32_t nr_gpr = 1;    // skip one GPR register for 'that'
        uint32_t nr_fpr = 0;
        uint64_t value;

        for (i = 0; i < paramCount; i++) {
            const nsXPTParamInfo& param = info->GetParam(i);
            const nsXPTType& type = param.GetType();
            nsXPTCMiniVariant* dp = ¶mBuffer[i];

            if (i == indexOfJSContext) {
                if (nr_gpr < GPR_COUNT)
                    nr_gpr++;
                else
                    ap++;
            }

            if (!param.IsOut() && type == nsXPTType::T_DOUBLE) {
                if (nr_fpr < FPR_COUNT)
                    dp->val.d = fpregs[nr_fpr++];
                else
                    dp->val.d = *(double*) ap++;
                continue;
            }
            else if (!param.IsOut() && type == nsXPTType::T_FLOAT) {
                if (nr_fpr < FPR_COUNT)
                    // The value in %xmm register is already prepared to
                    // be retrieved as a float. Therefore, we pass the
                    // value verbatim, as a double without conversion.
                    dp->val.d = fpregs[nr_fpr++];
                else
                    dp->val.f = *(float*) ap++;
                continue;
            }
            else {
                if (nr_gpr < GPR_COUNT)
                    value = gpregs[nr_gpr++];
                else
                    value = *ap++;
            }

            if (param.IsOut() || !type.IsArithmetic()) {
                dp->val.p = (void*) value;
                continue;
            }

            switch (type) {
            case nsXPTType::T_I8:      dp->val.i8  = (int8_t)   value; break;
            case nsXPTType::T_I16:     dp->val.i16 = (int16_t)  value; break;
            case nsXPTType::T_I32:     dp->val.i32 = (int32_t)  value; break;
            case nsXPTType::T_I64:     dp->val.i64 = (int64_t)  value; break;
            case nsXPTType::T_U8:      dp->val.u8  = (uint8_t)  value; break;
            case nsXPTType::T_U16:     dp->val.u16 = (uint16_t) value; break;
            case nsXPTType::T_U32:     dp->val.u32 = (uint32_t) value; break;
            case nsXPTType::T_U64:     dp->val.u64 = (uint64_t) value; break;
            // Cast to uint8_t first, to remove garbage on upper 56 bits.
            case nsXPTType::T_BOOL:    dp->val.b   = (bool)(uint8_t)   value; break;
            case nsXPTType::T_CHAR:    dp->val.c   = (char)     value; break;
            case nsXPTType::T_WCHAR:   dp->val.wc  = (wchar_t)  value; break;

            default:
                NS_ERROR("bad type");
                break;
            }
        }

        nsresult result = self->mOuter->CallMethod((uint16_t) methodIndex, info,
                                                   paramBuffer);

        return result;
    }