develooper Front page | perl.perl5.porters | Postings from March 2008

refactor dump.c to eliminate ~150 lines of cut-paste code

Thread Next
From:
Jim Cromie
Date:
March 19, 2008 10:53
Subject:
refactor dump.c to eliminate ~150 lines of cut-paste code
Message ID:
47E1530C.7000609@gmail.com

this patch set reworks dump.c to eliminate ~150 lines
of pseudo-duplicated code.  I say pseudo because someone has
since added a temporary variable which hides the duplication
from tools like cut-paste-detector.

The patches affect only -Dmad -DDEBUGGING builds,
reducing object size by ~1500 bytes on threaded, ~1350 non-threaded.
as follows:  (-0 is unaltered blead)

  89672       0       0   89672   15e48 mmad-0/dump.o
  89672       0       0   89672   15e48 mmad-1/dump.o
  89672       0       0   89672   15e48 mmad-2/dump.o
  89596       0       0   89596   15dfc mmad-3/dump.o
  87432       0       0   87432   15588 mmad-4/dump.o
  87432       0       0   87432   15588 mmad-5/dump.o
  87432       0       0   87432   15588 mmad-6/dump.o
  87442       0       0   87442   15592 mmad-7/dump.o
  87298       0       0   87298   15502 mmad-8/dump.o
  92626       0       0   92626   169d2 mmadthr-0/dump.o
  92626       0       0   92626   169d2 mmadthr-1/dump.o
  92626       0       0   92626   169d2 mmadthr-2/dump.o
  92674       0       0   92674   16a02 mmadthr-3/dump.o
  90290       0       0   90290   160b2 mmadthr-4/dump.o
  90290       0       0   90290   160b2 mmadthr-5/dump.o
  90290       0       0   90290   160b2 mmadthr-6/dump.o
  90300       0       0   90300   160bc mmadthr-7/dump.o
  90124       0       0   90124   1600c mmadthr-8/dump.o

IIRC, the patch enlarges a -DDEBUGGING (no -Dmad) build by ~50 bytes.


Ive submitted this (and/or parts of it) several times before,
and am hoping to get more traction this time.

http://marc.info/?l=perl5-porters&m=116547041216822&w=2
http://marc.info/?l=perl5-porters&m=117212256302899&w=2
http://marc.info/?l=perl5-porters&m=117391014721169&w=2
http://marc.info/?l=perl5-porters&m=117886564002918&w=2
http://marc.info/?l=perl5-porters&m=118160917718640&w=2


Ive done this as individual patches, in the hope that they'd be easier to
review this way.

diff.mad-seq-nr        fix sequence diffs between -Dx on -Dmad vs -Umad 
builds
diff.mad-test          test mad output, establish baseline
diff.dump-test         test -Dx dump output
diff.dump-refactor     pull S_dump_op_flags(), S_dump_op_flags_private() 
out of Perl_do_op_dump()
diff.dump-reduce       delete dup'd code from Perl_do_op_xmldump(), call 
new funcs..
diff.dump-one-opmad    tweak ifdef placement per earlier feedback
diff.dump-reindent     whitespace only
diff.dump-embed        per earlier feedback
diff.dump-mortalize    simplify 'ownership' of returned SVs


Im also attaching a rolled-up version if thats preferred.



Notes:

1 - I dont really agree with changes in diff.dump-embed. 

It seems pointless to expose a static function, but to ifdef it away 
except for dump.c,
so that its invisibility outside dump.c is restored.  Leaving it static 
is bog-standard
C coding practice, and requires no explanation.

2 - fix premature return in S_sequence

The following ifdef PERL_MAD code causes -Dx renderings to have
different sequence numberings on -Dmad builds.


STATIC void
S_sequence(pTHX_ register const OP *o)
{
    dVAR;
    const OP *oldop = NULL;

    if (!o)
        return;

#ifdef PERL_MAD
    if (o->op_next == 0)
        return;
#endif


[jimc@harpo bleadperl]$ ./perl -Ilib -Dx -e 'print foo'
{
1   TYPE = leave  ===> DONE
    TARG = 1
    FLAGS = (VOID,KIDS,PARENS)
    PRIVATE = (REFCOUNTED)
    REFCNT = 1
    {
2       TYPE = enter  ===> 3
    }

[jimc@harpo mmad-0]$ ./perl -Ilib -Dx -e 'print foo'
{
    TYPE = leave  ===> DONE
    TARG = 1
    FLAGS = (VOID,KIDS,PARENS)
    PRIVATE = (REFCOUNTED)
    REFCNT = 1
    {
1       TYPE = enter  ===> 2
    }


When I inquired wrt its purpose, the answer was basically
"I dunno, Larry did it".  As all tests pass, both nonthread & thread,
I conclude it was a temporary workaround that was overlooked.



Sooo, how can I help to get these applied to blead ?


Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About