http://pmd.sourceforge.net/cpd.html
When run on the perl5 source, it finds quite a lot of duplication. Some of
it seems to be in the middle of autogenerated tables. Quite a bit is
duplication between code in the win32, wince and netware subdirectories.
And some of it might be ripe for some pruning into static functions, or
tweaking. eg:
Found a 21 line (126 tokens) duplication in the following files:
Starting at line 2503 of /Users/nick/p4perl/perl/pp_pack.c
Starting at line 2555 of /Users/nick/p4perl/perl/pp_pack.c
else {
char *from, *result, *in;
SV *norm;
STRLEN len;
bool done;
/* Copy string and check for compliance */
from = SvPV(fromstr, len);
if ((norm = is_an_int(from, len)) == NULL)
Perl_croak(aTHX_ "Can only compress unsigned integers in pack");
New('w', result, len, char);
in = result + len;
done = FALSE;
while (!done)
*--in = div128(norm, &done) | 0x80;
result[len - 1] &= 0x7F; /* clear continue bit */
sv_catpvn(cat, in, (result + len) - in);
Safefree(result);
SvREFCNT_dec(norm); /* free norm */
}
=====================================================================
Found a 15 line (92 tokens) duplication in the following files:
Starting at line 229 of /Users/nick/p4perl/perl/mg.c
Starting at line 259 of /Users/nick/p4perl/perl/mg.c
I32 len;
for (mg = SvMAGIC(sv); mg; mg = mg->mg_moremagic) {
MGVTBL* vtbl = mg->mg_virtual;
if (vtbl && vtbl->svt_len) {
I32 mgs_ix;
mgs_ix = SSNEW(sizeof(MGS));
save_magic(mgs_ix, sv);
/* omit MGf_GSKIP -- not changed here */
len = CALL_FPTR(vtbl->svt_len)(aTHX_ sv, mg);
restore_magic(aTHX_ INT2PTR(void*, (IV)mgs_ix));
return len;
}
}
=====================================================================
I've put the full output of my run online at:
http://opensource.fotango.com/~nclark/perl_code_duplication.text
The app itself can be run from http://pmd.sourceforge.net/cpd.jnlp
(select C++ to parse perl's C++ code, and it works best if you remove
Encode's generated files first. My run doesn't have duplicated XS code,
as it was done after a make realclean. so its generate C code was not
present)
Nicholas Clark