Skip to content

Commit

Permalink
change suffix from _op to _with_object in custom op code changes
Browse files Browse the repository at this point in the history
  • Loading branch information
demerphq committed Mar 16, 2014
1 parent 9a61fda commit e041269
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 39 deletions.
25 changes: 13 additions & 12 deletions Perl/Decoder/Decoder.xs
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ THX_ck_entersub_args_sereal_decoder(pTHX_ OP *entersubop, GV *namegv, SV *ckobj)
return entersubop;

/* If we get here, we can replace the entersub with a suitable
* sereal_decode_op custom OP. */
* sereal_decode_with_object custom OP. */

if (arity > min_arity && (opopt & OPOPT_DO_BODY)) {
opopt |= OPOPT_OUTARG_BODY;
Expand Down Expand Up @@ -197,27 +197,28 @@ BOOT:
char const *name_suffix;
U8 opopt;
} const funcs_to_install[] = {
{ "", OPOPT_DO_BODY },
{ "_only_header", OPOPT_DO_HEADER },
{ "_with_header", (OPOPT_DO_BODY|OPOPT_DO_HEADER) },
{ "_with_offset", (OPOPT_DO_BODY|OPOPT_OFFSET) },
{ "_only_header_with_offset", (OPOPT_DO_HEADER|OPOPT_OFFSET) },
{ "_with_header_and_offset",
(OPOPT_DO_BODY|OPOPT_DO_HEADER|OPOPT_OFFSET) },
{ "", OPOPT_DO_BODY },
{ "_only_header", OPOPT_DO_HEADER },
{ "_with_header", (OPOPT_DO_BODY|OPOPT_DO_HEADER) },
{ "_with_offset", (OPOPT_DO_BODY|OPOPT_OFFSET) },
{ "_only_header_with_offset", (OPOPT_DO_HEADER|OPOPT_OFFSET) },
{ "_with_header_and_offset", (OPOPT_DO_BODY|OPOPT_DO_HEADER|OPOPT_OFFSET) },
/*012345678901234567890123*/
}, *fti;
int i;
#if USE_CUSTOM_OPS
{
XOP *xop;
Newxz(xop, 1, XOP);
XopENTRY_set(xop, xop_name, "sereal_decode_op");
XopENTRY_set(xop, xop_desc, "sereal_decode_op");
XopENTRY_set(xop, xop_name, "sereal_decode_with_object");
XopENTRY_set(xop, xop_desc, "sereal_decode_with_object");
XopENTRY_set(xop, xop_class, OA_UNOP);
Perl_custom_op_register(aTHX_ THX_pp_sereal_decode, xop);
}
#endif /* USE_CUSTOM_OPS */
for (i = sizeof(funcs_to_install)/sizeof(*fti); i--; ) {
char name[58];
# define LONG_CLASS_FMT "Sereal::Decoder::sereal_decode%s_with_object"
char name[sizeof(LONG_CLASS_FMT)+24];
char proto[7], *p = proto;
U8 opopt;
I32 cv_private;
Expand Down Expand Up @@ -270,7 +271,7 @@ BOOT:
}
*p = 0;
/* setup the name of the sub */
sprintf(name, "Sereal::Decoder::sereal_decode%s_op", fti->name_suffix);
sprintf(name, LONG_CLASS_FMT, fti->name_suffix);
cv = newXSproto_portable(name, THX_xsfunc_sereal_decode, __FILE__,
proto);
CvXSUBANY(cv).any_i32 = cv_private;
Expand Down
10 changes: 5 additions & 5 deletions Perl/Decoder/lib/Sereal/Decoder.pm
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ sub _test_compat {return(@$TestCompat, $VERSION)}
use Exporter 'import';
our @EXPORT_OK = qw(
decode_sereal looks_like_sereal decode_sereal_with_header_data
sereal_decode_op sereal_decode_with_header_op
sereal_decode_with_object sereal_decode_with_header_with_object
);
our %EXPORT_TAGS = (all => \@EXPORT_OK);
# export by default if run from command line
Expand All @@ -38,7 +38,7 @@ Sereal::Decoder - Fast, compact, powerful binary deserialization
=head1 SYNOPSIS
use Sereal::Decoder
qw(decode_sereal sereal_decode_op looks_like_sereal);
qw(decode_sereal sereal_decode_with_object looks_like_sereal);
my $decoder = Sereal::Decoder->new({...options...});
Expand All @@ -49,8 +49,8 @@ Sereal::Decoder - Fast, compact, powerful binary deserialization
$structure = $decoder->decode($blob);
# alternatively functional interface:
sereal_decode_op($decoder, $blob, $structure);
$structure = sereal_decode_op($decoder, $blob);
sereal_decode_with_object($decoder, $blob, $structure);
$structure = sereal_decode_with_object($decoder, $blob);
# slower functional interface with no persistent objects:
decode_sereal($blob, {... options ...}, $structure);
Expand Down Expand Up @@ -218,7 +218,7 @@ For reference, sereal's magic string is a four byte string C<=srl>.
=head1 EXPORTABLE FUNCTIONS
=head2 sereal_decode_op
=head2 sereal_decode_with_object
The functional interface that is equivalent to using C<decode>. Takes a
decoder object reference as first argument, followed by a byte string
Expand Down
30 changes: 15 additions & 15 deletions Perl/Encoder/Encoder.xs
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@
# define USE_CUSTOM_OPS 0
#endif

#define pp1_sereal_encode_op(has_hdr) THX_pp1_sereal_encode_op(aTHX_ has_hdr)
#define pp1_sereal_encode_with_object(has_hdr) THX_pp1_sereal_encode_with_object(aTHX_ has_hdr)
static void
THX_pp1_sereal_encode_op(pTHX_ U8 has_hdr)
THX_pp1_sereal_encode_with_object(pTHX_ U8 has_hdr)
{
SV *encoder_ref_sv, *encoder_sv, *body_sv, *header_sv;
srl_encoder_t *enc;
Expand Down Expand Up @@ -68,14 +68,14 @@ THX_pp1_sereal_encode_op(pTHX_ U8 has_hdr)
#if USE_CUSTOM_OPS

static OP *
THX_pp_sereal_encode_op(pTHX)
THX_pp_sereal_encode_with_object(pTHX)
{
pp1_sereal_encode_op(PL_op->op_private);
pp1_sereal_encode_with_object(PL_op->op_private);
return NORMAL;
}

static OP *
THX_ck_entersub_args_sereal_encode_op(pTHX_ OP *entersubop, GV *namegv, SV *ckobj)
THX_ck_entersub_args_sereal_encode_with_object(pTHX_ OP *entersubop, GV *namegv, SV *ckobj)
{
OP *pushop, *firstargop, *cvop, *lastargop, *argop, *newop;
int arity;
Expand Down Expand Up @@ -103,30 +103,30 @@ THX_ck_entersub_args_sereal_encode_op(pTHX_ OP *entersubop, GV *namegv, SV *ckob
return entersubop;

/* If we get here, we can replace the entersub with a suitable
* sereal_encode_op custom OP. */
* sereal_encode_with_object custom OP. */

pushop->op_sibling = cvop;
lastargop->op_sibling = NULL;
op_free(entersubop);
newop = newUNOP(OP_CUSTOM, 0, firstargop);
newop->op_private = arity == 3;
newop->op_ppaddr = THX_pp_sereal_encode_op;
newop->op_ppaddr = THX_pp_sereal_encode_with_object;

return newop;
}

#endif /* USE_CUSTOM_OPS */

static void
THX_xsfunc_sereal_encode_op(pTHX_ CV *cv)
THX_xsfunc_sereal_encode_with_object(pTHX_ CV *cv)
{
dMARK;
dSP;
SSize_t arity = SP - MARK;
PERL_UNUSED_ARG(cv);
if (arity < 2 || arity > 3)
croak("bad Sereal encoder usage");
pp1_sereal_encode_op(arity == 3);
pp1_sereal_encode_with_object(arity == 3);
}

MODULE = Sereal::Encoder PACKAGE = Sereal::Encoder
Expand All @@ -138,18 +138,18 @@ BOOT:
{
XOP *xop;
Newxz(xop, 1, XOP);
XopENTRY_set(xop, xop_name, "sereal_encode_op");
XopENTRY_set(xop, xop_desc, "sereal_encode_op");
XopENTRY_set(xop, xop_name, "sereal_encode_with_object");
XopENTRY_set(xop, xop_desc, "sereal_encode_with_object");
XopENTRY_set(xop, xop_class, OA_UNOP);
Perl_custom_op_register(aTHX_ THX_pp_sereal_encode_op, xop);
Perl_custom_op_register(aTHX_ THX_pp_sereal_encode_with_object, xop);
}
#endif /* USE_CUSTOM_OPS */
{
GV *gv;
CV *cv = newXSproto_portable("Sereal::Encoder::sereal_encode_op",
THX_xsfunc_sereal_encode_op, __FILE__, "$$;$");
CV *cv = newXSproto_portable("Sereal::Encoder::sereal_encode_with_object",
THX_xsfunc_sereal_encode_with_object, __FILE__, "$$;$");
#if USE_CUSTOM_OPS
cv_set_call_checker(cv, THX_ck_entersub_args_sereal_encode_op, (SV*)cv);
cv_set_call_checker(cv, THX_ck_entersub_args_sereal_encode_with_object, (SV*)cv);
#endif /* USE_CUSTOM_OPS */
gv = gv_fetchpv("Sereal::Encoder::encode", GV_ADDMULTI, SVt_PVCV);
GvCV_set(gv, cv);
Expand Down
10 changes: 5 additions & 5 deletions Perl/Encoder/lib/Sereal/Encoder.pm
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ my $TestCompat = [ map sprintf("%.2f", $_/100), reverse( 200 .. int($num_version
sub _test_compat {return(@$TestCompat, $VERSION)}

use Exporter 'import';
our @EXPORT_OK = qw(encode_sereal encode_sereal_with_header_data sereal_encode_op);
our @EXPORT_OK = qw(encode_sereal encode_sereal_with_header_data sereal_encode_with_object);
our %EXPORT_TAGS = (all => \@EXPORT_OK);
# export by default if run from command line
our @EXPORT = ((caller())[1] eq '-e' ? @EXPORT_OK : ());
Expand All @@ -34,12 +34,12 @@ Sereal::Encoder - Fast, compact, powerful binary serialization
=head1 SYNOPSIS
use Sereal::Encoder qw(encode_sereal sereal_encode_op);
use Sereal::Encoder qw(encode_sereal sereal_encode_with_object);
my $encoder = Sereal::Encoder->new({...options...});
my $out = $encoder->encode($structure);
# alternatively:
$out = sereal_encode_op($encoder, $structure);
$out = sereal_encode_with_object($encoder, $structure);
# slower functional interface with no persistent objects:
$out = encode_sereal($structure, {... options ...});
Expand Down Expand Up @@ -275,7 +275,7 @@ L<Sereal::Decoder>.
=head1 EXPORTABLE FUNCTIONS
=head2 sereal_encode_op
=head2 sereal_encode_with_object
The functional interface that is equivalent to using C<encode>. Takes an
encoder object reference as first argument, followed by a data structure
Expand All @@ -296,7 +296,7 @@ it cannot reuse the encoder object.
=head1 PERFORMANCE
If you care about performance at all, then use L</sereal_encode_op> or the
If you care about performance at all, then use L</sereal_encode_with_object> or the
OO interface instead of L</encode_sereal>. It's a significant difference
in performance if you are serializing small data structures.
Expand Down
4 changes: 2 additions & 2 deletions Perl/shared/t/lib/Sereal/TestSet.pm
Original file line number Diff line number Diff line change
Expand Up @@ -726,8 +726,8 @@ sub run_roundtrip_tests_internal {
sub {$encoder->encode($_[0])},
sub {$decoder->decode($_[0])}],
['functional with object',
sub {Sereal::Encoder::sereal_encode_op($encoder, $_[0])},
sub {Sereal::Decoder::sereal_decode_op($decoder, $_[0])}],
sub {Sereal::Encoder::sereal_encode_with_object($encoder, $_[0])},
sub {Sereal::Decoder::sereal_decode_with_object($decoder, $_[0])}],
['header-body',
sub {$encoder->encode($_[0], 123456789)}, # header data is abitrary to stand out for debugging
sub {$decoder->decode($_[0])}],
Expand Down

0 comments on commit e041269

Please sign in to comment.