diff options
author | Gurusamy Sarathy <gsar@cpan.org> | 2000-03-08 19:27:02 +0000 |
---|---|---|
committer | Gurusamy Sarathy <gsar@cpan.org> | 2000-03-08 19:27:02 +0000 |
commit | 0f1923bdafbbf46153592d4c0bb426b7e17d90d7 (patch) | |
tree | b87f82b74533884b912b6242e09d20a4aee7be4e /ext/Data | |
parent | faa7e5bbaa1a624cf61859998ab6ab0a1323ed35 (diff) | |
download | perl-0f1923bdafbbf46153592d4c0bb426b7e17d90d7.tar.gz |
make Dump() call the XSUB implementation transparently (modified
version of patch suggested by David Boyce <dsb@world.std.com>)
p4raw-id: //depot/perl@5621
Diffstat (limited to 'ext/Data')
-rw-r--r-- | ext/Data/Dumper/Dumper.pm | 32 | ||||
-rw-r--r-- | ext/Data/Dumper/Dumper.xs | 16 |
2 files changed, 17 insertions, 31 deletions
diff --git a/ext/Data/Dumper/Dumper.pm b/ext/Data/Dumper/Dumper.pm index c86299c619..93b87f9aba 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<new> method on its arguments before dumping the object immediately. -=item I<$OBJ>->Dumpxs I<or> I<PACKAGE>->Dumpxs(I<ARRAYREF [>, I<ARRAYREF]>) - -This method is available if you were able to compile and install the XSUB -extension to C<Data::Dumper>. It is exactly identical to the C<Dump> 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<n> in the output, where I<n> is a numeric suffix. Will return a list of strings in an array context. -=item DumperX(I<LIST>) - -Identical to the C<Dumper()> function above, but this calls the XSUB -implementation. Only available if you were able to compile and install -the XSUB extensions in C<Data::Dumper>. - =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<Dumpxs()> method does not honor this -flag yet. +penalty, the default is 0. C<Dump()> will run slower if this flag is set, +since the fast XSUB implementation doesn't support it yet. =item $Data::Dumper::Terse I<or> I<$OBJ>->Terse(I<[NEWVAL]>) @@ -1031,8 +1023,8 @@ to have, you can use the C<Seen> method to pre-seed the internal reference table and make the dumped output point to them, instead. See L<EXAMPLES> above. -The C<Useqq> flag is not honored by C<Dumpxs()> (it always outputs -strings in single quotes). +The C<Useqq> flag makes Dump() run slower, since the XSUB implementation +does not support it. SCALAR objects have the weirdest looking C<bless> workaround. diff --git a/ext/Data/Dumper/Dumper.xs b/ext/Data/Dumper/Dumper.xs index 6394a63b28..990ea74699 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; |