1
/* Must be defined before including Perl header files or we slow down by 2x! */
2
#define PERL_NO_GET_CONTEXT
8
#define NEED_newSV_type
11
#include "srl_encoder.h"
12
#include "srl_buffer.h"
14
/* Generated code for exposing C constants to Perl */
15
#include "srl_protocol.h"
16
#include "const-c.inc"
20
MODULE = Sereal::Encoder PACKAGE = Sereal::Encoder
24
new(CLASS, opt = NULL)
28
RETVAL = srl_build_encoder_struct(aTHX_ opt);
29
RETVAL->flags |= SRL_F_REUSE_ENCODER;
36
srl_destroy_encoder(aTHX_ enc);
44
srl_dump_data_structure(aTHX_ enc, src);
45
assert(enc->pos > enc->buf_start);
46
/* We always copy the string since we might reuse the string buffer. That means
47
* we already have to do a malloc and we might as well use the opportunity to
48
* allocate only as much memory as we really need to hold the output. */
49
ST(0) = sv_2mortal(newSVpvn(enc->buf_start, (STRLEN)BUF_POS_OFS(enc)));
53
encode_sereal(src, opt = NULL)
59
enc = srl_build_encoder_struct(aTHX_ opt);
61
srl_dump_data_structure(aTHX_ enc, src);
62
/* Avoid copy by stealing string buffer if it is not too large.
63
* This makes sense in the functional interface since the string
64
* buffer isn't ever going to be reused. */
65
assert(enc->buf_start < enc->pos);
66
if (BUF_POS_OFS(enc) > 20 && BUF_SPACE(enc) < BUF_POS_OFS(enc) ) {
67
/* If not wasting more than 2x memory - FIXME fungible */
68
SV *sv = sv_2mortal(newSV_type(SVt_PV));
70
SvPV_set(sv, enc->buf_start);
71
SvLEN_set(sv, BUF_SIZE(enc));
72
SvCUR_set(sv, BUF_POS_OFS(enc));
75
enc->buf_start = enc->pos = NULL; /* no need to free these guys now */
78
ST(0) = sv_2mortal(newSVpvn(enc->buf_start, (STRLEN)BUF_POS_OFS(enc)));
83
MODULE = Sereal::Encoder PACKAGE = Sereal::Encoder::Constants
88
MODULE = Sereal::Encoder PACKAGE = Sereal::Encoder::_ptabletest
98
char fail[5] = "not ";
101
tbl = PTABLE_new_size(10);
102
for (i = 0; i < (UV)n; ++i) {
103
PTABLE_store(tbl, (void *)(1000+i), (void *)(1000+i));
106
for (i = 0; i < (UV)n; ++i) {
107
const UV res = (UV)PTABLE_fetch(tbl, (void *)(1000+i));
108
printf("%sok %u - fetch %u\n", (res == (UV)(1000+i)) ? noop : fail, (unsigned int)(1+i), (unsigned int)(i+1));
110
iter = PTABLE_iter_new(tbl);
111
while ( NULL != (ent = PTABLE_iter_next(iter)) ) {
112
const UV res = ((UV)ent->value) - 1000;
118
for (i = 0; i < (UV)n; ++i) {
119
printf("%sok %u - iter %u\n", check[i], (unsigned int)(21+i), (unsigned int)(i+1));
121
PTABLE_iter_free(iter);