Math::Factor::XS
optimizando la función
matches
:
26 matches(number, ...) 27 long number 28 PROTOTYPE: $@ 29 INIT: 30 long base[items], cmp[items], prev_base[items]; 31 long b, c, i, p = 0; 32 bool Skip_multiple, skip = 0; 33 SV* skip_multiple; 34 AV* match; 35 PPCODE: 36 skip_multiple = get_sv("Math::Factor::XS::Skip_multiple", FALSE); 37 Skip_multiple = skip_multiple != NULL ? SvIV(skip_multiple) : 0; 38 for (i = 0; i < items; i++) { 39 base[i] = SvIV(ST(i)); 40 cmp[i] = SvIV(ST(i)); 41 } 42 for (b = 0; b < items; b++) { 43 for (c = 0; c < items; c++) { 44 if (cmp[c] >= base[b] && base[b] * cmp[c] == number) { 45 if (Skip_multiple) { 46 skip = 0; 47 for (i = 0; i < p; i++) { 48 if (base[b] % prev_base[i] == 0) skip = 1; 49 } 50 } 51 if (!skip) { 52 match = (AV*)sv_2mortal((SV*)newAV()); 53 av_push(match, newSViv(base[b])); 54 av_push(match, newSViv(cmp[c])); 55 EXTEND(SP,2); 56 PUSHs(sv_2mortal(newRV((SV*)match))); 57 if (Skip_multiple) { 58 prev_base[p++] = base[b]; 59 } 60 } 61 } 62 } 63 }Proceda a realizar los siguientes pasos:
EXTEND(SP,2)
)
items
(líneas 42 y 43)
o puede reescribirse el algoritmo usando un sólo bucle de tamaño
items
?
Casiano Rodríguez León