From: Gurusamy Sarathy Date: Wed, 8 Mar 2000 19:27:02 +0000 (+0000) Subject: make Dump() call the XSUB implementation transparently (modified X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=0f1923bdafbbf46153592d4c0bb426b7e17d90d7;p=p5sagit%2Fp5-mst-13.2.git make Dump() call the XSUB implementation transparently (modified version of patch suggested by David Boyce ) p4raw-id: //depot/perl@5621 --- diff --git a/ext/Data/Dumper/Dumper.pm b/ext/Data/Dumper/Dumper.pm index c86299c..93b87f9 100644 --- a/ext/Data/Dumper/Dumper.pm +++ b/ext/Data/Dumper/Dumper.pm @@ -146,11 +146,17 @@ sub Names { sub DESTROY {} +sub Dump { + return &Dumpxs + unless $Data::Dumper::Useqq || (ref($_[0]) && $_[0]->{useqq}); + return &Dumpperl; +} + # # dump the refs in the current dumper object. # expects same args as new() if called via package name. # -sub Dump { +sub Dumpperl { my($s) = shift; my(@out, $val, $name); my($i) = 0; @@ -440,9 +446,7 @@ sub Dumper { return Data::Dumper->Dump([@_]); } -# -# same, only calls the XS version -# +# compat stub sub DumperX { return Data::Dumper->Dumpxs([@_], []); } @@ -687,12 +691,6 @@ of strings corresponding to the supplied values. The second form, for convenience, simply calls the C method on its arguments before dumping the object immediately. -=item I<$OBJ>->Dumpxs I I->Dumpxs(I, I) - -This method is available if you were able to compile and install the XSUB -extension to C. It is exactly identical to the C method -above, only about 4 to 5 times faster, since it is written entirely in C. - =item I<$OBJ>->Seen(I<[HASHREF]>) Queries or adds to the internal table of already encountered references. @@ -736,12 +734,6 @@ configuration options below. The values will be named C<$VAR>I in the output, where I is a numeric suffix. Will return a list of strings in an array context. -=item DumperX(I) - -Identical to the C function above, but this calls the XSUB -implementation. Only available if you were able to compile and install -the XSUB extensions in C. - =back =head2 Configuration Variables or Methods @@ -797,8 +789,8 @@ When set, enables the use of double quotes for representing string values. Whitespace other than space will be represented as C<[\n\t\r]>, "unsafe" characters will be backslashed, and unprintable characters will be output as quoted octal integers. Since setting this variable imposes a performance -penalty, the default is 0. The C method does not honor this -flag yet. +penalty, the default is 0. C will run slower if this flag is set, +since the fast XSUB implementation doesn't support it yet. =item $Data::Dumper::Terse I I<$OBJ>->Terse(I<[NEWVAL]>) @@ -1031,8 +1023,8 @@ to have, you can use the C method to pre-seed the internal reference table and make the dumped output point to them, instead. See L above. -The C flag is not honored by C (it always outputs -strings in single quotes). +The C flag makes Dump() run slower, since the XSUB implementation +does not support it. SCALAR objects have the weirdest looking C workaround. diff --git a/ext/Data/Dumper/Dumper.xs b/ext/Data/Dumper/Dumper.xs index 6394a63..990ea74 100644 --- a/ext/Data/Dumper/Dumper.xs +++ b/ext/Data/Dumper/Dumper.xs @@ -711,23 +711,17 @@ Data_Dumper_Dumpxs(href, ...) I32 gimme = GIMME; if (!SvROK(href)) { /* call new to get an object first */ - SV *valarray; - SV *namearray; - - if (items == 3) { - valarray = ST(1); - namearray = ST(2); - } - else - croak("Usage: Data::Dumper::Dumpxs(PACKAGE, VAL_ARY_REF, NAME_ARY_REF)"); + if (items < 2) + croak("Usage: Data::Dumper::Dumpxs(PACKAGE, VAL_ARY_REF, [NAME_ARY_REF])"); ENTER; SAVETMPS; PUSHMARK(sp); XPUSHs(href); - XPUSHs(sv_2mortal(newSVsv(valarray))); - XPUSHs(sv_2mortal(newSVsv(namearray))); + XPUSHs(sv_2mortal(newSVsv(ST(1)))); + if (items >= 3) + XPUSHs(sv_2mortal(newSVsv(ST(2)))); PUTBACK; i = perl_call_method("new", G_SCALAR); SPAGAIN; diff --git a/pod/perldelta.pod b/pod/perldelta.pod index 8fc8efe..8e62de0 100644 --- a/pod/perldelta.pod +++ b/pod/perldelta.pod @@ -1435,6 +1435,9 @@ change#4052 A C setting can be specified to avoid venturing too deeply into deep data structures. See L. +The XSUB implementation of Dump() is now automatically called if the +C setting is not in use. + Dumping C objects works correctly. =item DB