ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/CBOR-XS/XS.xs
(Generate patch)

Comparing CBOR-XS/XS.xs (file contents):
Revision 1.22 by root, Wed Nov 20 15:05:46 2013 UTC vs.
Revision 1.26 by root, Fri Nov 22 09:40:13 2013 UTC

54 CBOR_TAG_MIME = 36, // mime message rfc2045, utf-8 54 CBOR_TAG_MIME = 36, // mime message rfc2045, utf-8
55 55
56 CBOR_TAG_MAGIC = 55799 // self-describe cbor 56 CBOR_TAG_MAGIC = 55799 // self-describe cbor
57}; 57};
58 58
59#define F_SHRINK 0x00000001UL 59#define F_SHRINK 0x00000001UL
60#define F_ALLOW_UNKNOWN 0x00000002UL 60#define F_ALLOW_UNKNOWN 0x00000002UL
61#define F_ALLOW_SHARING 0x00000004UL //TODO 61#define F_ALLOW_SHARING 0x00000004UL //TODO
62#define F_DEDUP_STRINGS 0x00000008UL //TODO 62#define F_ALLOW_STRINGREF 0x00000008UL //TODO
63 63
64#define INIT_SIZE 32 // initial scalar size to be allocated 64#define INIT_SIZE 32 // initial scalar size to be allocated
65 65
66#define SB do { 66#define SB do {
67#define SE } while (0) 67#define SE } while (0)
223} 223}
224 224
225static void 225static void
226encode_str (enc_t *enc, int utf8, char *str, STRLEN len) 226encode_str (enc_t *enc, int utf8, char *str, STRLEN len)
227{ 227{
228 if (ecb_expect_false (enc->cbor.flags & F_DEDUP_STRINGS)) 228 if (ecb_expect_false (enc->cbor.flags & F_ALLOW_STRINGREF))
229 { 229 {
230 SV **svp = hv_fetch (enc->stringref[!!utf8], str, len, 1); 230 SV **svp = hv_fetch (enc->stringref[!!utf8], str, len, 1);
231 231
232 if (SvOK (*svp)) 232 if (SvOK (*svp))
233 { 233 {
269 SV **svp = av_fetch (av, i, 0); 269 SV **svp = av_fetch (av, i, 0);
270 encode_sv (enc, svp ? *svp : &PL_sv_undef); 270 encode_sv (enc, svp ? *svp : &PL_sv_undef);
271 } 271 }
272 272
273 --enc->depth; 273 --enc->depth;
274}
275
276ecb_inline void
277encode_he (enc_t *enc, HE *he)
278{
279} 274}
280 275
281static void 276static void
282encode_hv (enc_t *enc, HV *hv) 277encode_hv (enc_t *enc, HV *hv)
283{ 278{
515 enc.cur = SvPVX (enc.sv); 510 enc.cur = SvPVX (enc.sv);
516 enc.end = SvEND (enc.sv); 511 enc.end = SvEND (enc.sv);
517 512
518 SvPOK_only (enc.sv); 513 SvPOK_only (enc.sv);
519 514
520 if (cbor->flags & F_DEDUP_STRINGS) 515 if (cbor->flags & F_ALLOW_STRINGREF)
521 { 516 {
522 encode_tag (&enc, CBOR_TAG_STRINGREF_NAMESPACE); 517 encode_tag (&enc, CBOR_TAG_STRINGREF_NAMESPACE);
523 enc.stringref[0]= (HV *)sv_2mortal ((SV *)newHV ()); 518 enc.stringref[0]= (HV *)sv_2mortal ((SV *)newHV ());
524 enc.stringref[1]= (HV *)sv_2mortal ((SV *)newHV ()); 519 enc.stringref[1]= (HV *)sv_2mortal ((SV *)newHV ());
525 } 520 }
656decode_he (dec_t *dec, HV *hv) 651decode_he (dec_t *dec, HV *hv)
657{ 652{
658 // for speed reasons, we specialcase single-string 653 // for speed reasons, we specialcase single-string
659 // byte or utf-8 strings as keys, but only when !stringref 654 // byte or utf-8 strings as keys, but only when !stringref
660 655
661 if (expect_true (!dec->stringref)) 656 if (ecb_expect_true (!dec->stringref))
662 if (*dec->cur >= 0x40 && *dec->cur <= 0x40 + 27) 657 if (*dec->cur >= 0x40 && *dec->cur <= 0x40 + 27)
663 { 658 {
664 I32 len = decode_uint (dec); 659 I32 len = decode_uint (dec);
665 char *key = (char *)dec->cur; 660 char *key = (char *)dec->cur;
666 661
766 STRLEN len = decode_uint (dec); 761 STRLEN len = decode_uint (dec);
767 762
768 WANT (len); 763 WANT (len);
769 sv = newSVpvn (dec->cur, len); 764 sv = newSVpvn (dec->cur, len);
770 dec->cur += len; 765 dec->cur += len;
766
767 if (ecb_expect_false (dec->stringref)
768 && SvCUR (sv) >= minimum_string_length (AvFILLp (dec->stringref) + 1))
769 av_push (dec->stringref, SvREFCNT_inc_NN (sv));
771 } 770 }
772 771
773 if (utf8) 772 if (utf8)
774 SvUTF8_on (sv); 773 SvUTF8_on (sv);
775
776 if (ecb_expect_false (dec->stringref)
777 && SvCUR (sv) >= minimum_string_length (AvFILLp (dec->stringref) + 1))
778 av_push (dec->stringref, SvREFCNT_inc_NN (sv));
779 774
780 return sv; 775 return sv;
781 776
782fail: 777fail:
783 SvREFCNT_dec (sv); 778 SvREFCNT_dec (sv);
1104void shrink (CBOR *self, int enable = 1) 1099void shrink (CBOR *self, int enable = 1)
1105 ALIAS: 1100 ALIAS:
1106 shrink = F_SHRINK 1101 shrink = F_SHRINK
1107 allow_unknown = F_ALLOW_UNKNOWN 1102 allow_unknown = F_ALLOW_UNKNOWN
1108 allow_sharing = F_ALLOW_SHARING 1103 allow_sharing = F_ALLOW_SHARING
1109 dedup_strings = F_DEDUP_STRINGS 1104 allow_stringref = F_ALLOW_STRINGREF
1110 PPCODE: 1105 PPCODE:
1111{ 1106{
1112 if (enable) 1107 if (enable)
1113 self->flags |= ix; 1108 self->flags |= ix;
1114 else 1109 else
1120void get_shrink (CBOR *self) 1115void get_shrink (CBOR *self)
1121 ALIAS: 1116 ALIAS:
1122 get_shrink = F_SHRINK 1117 get_shrink = F_SHRINK
1123 get_allow_unknown = F_ALLOW_UNKNOWN 1118 get_allow_unknown = F_ALLOW_UNKNOWN
1124 get_allow_sharing = F_ALLOW_SHARING 1119 get_allow_sharing = F_ALLOW_SHARING
1125 get_dedup_strings = F_DEDUP_STRINGS 1120 get_allow_stringref = F_ALLOW_STRINGREF
1126 PPCODE: 1121 PPCODE:
1127 XPUSHs (boolSV (self->flags & ix)); 1122 XPUSHs (boolSV (self->flags & ix));
1128 1123
1129void max_depth (CBOR *self, U32 max_depth = 0x80000000UL) 1124void max_depth (CBOR *self, U32 max_depth = 0x80000000UL)
1130 PPCODE: 1125 PPCODE:

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines