--- JSON-XS/XS.xs 2007/06/06 14:52:49 1.35 +++ JSON-XS/XS.xs 2007/06/11 03:18:07 1.38 @@ -34,7 +34,7 @@ #define INIT_SIZE 32 // initial scalar size to be allocated #define INDENT_STEP 3 // spaces per indentation level -#define SHORT_STRING_LEN 512 // special-case strings of up to this size +#define SHORT_STRING_LEN 16384 // special-case strings of up to this size #define SB do { #define SE } while (0) @@ -508,11 +508,11 @@ // we assume we can always read an IV as a UV if (SvUV (sv) & ~(UV)0x7fff) { - need (enc, 32); + need (enc, sizeof (UV) * 3); enc->cur += SvIsUV(sv) - ? snprintf (enc->cur, 32, "%"UVuf, (UV)SvUVX (sv)) - : snprintf (enc->cur, 32, "%"IVdf, (IV)SvIVX (sv)); + ? snprintf (enc->cur, sizeof (UV) * 3, "%"UVuf, (UV)SvUVX (sv)) + : snprintf (enc->cur, sizeof (UV) * 3, "%"IVdf, (IV)SvIVX (sv)); } else { @@ -531,11 +531,11 @@ char digit, nz = 0; - digit = u >> 28; *enc->cur = digit + '0'; nz |= digit; enc->cur += nz ? 1 : 0; u = (u & 0xfffffff) * 5; - digit = u >> 27; *enc->cur = digit + '0'; nz |= digit; enc->cur += nz ? 1 : 0; u = (u & 0x7ffffff) * 5; - digit = u >> 26; *enc->cur = digit + '0'; nz |= digit; enc->cur += nz ? 1 : 0; u = (u & 0x3ffffff) * 5; - digit = u >> 25; *enc->cur = digit + '0'; nz |= digit; enc->cur += nz ? 1 : 0; u = (u & 0x1ffffff) * 5; - digit = u >> 24; *enc->cur = digit + '0'; nz |= digit; enc->cur += 1; + digit = u >> 28; *enc->cur = digit + '0'; enc->cur += (nz = nz || digit); u = (u & 0xfffffff) * 5; + digit = u >> 27; *enc->cur = digit + '0'; enc->cur += (nz = nz || digit); u = (u & 0x7ffffff) * 5; + digit = u >> 26; *enc->cur = digit + '0'; enc->cur += (nz = nz || digit); u = (u & 0x3ffffff) * 5; + digit = u >> 25; *enc->cur = digit + '0'; enc->cur += (nz = nz || digit); u = (u & 0x1ffffff) * 5; + digit = u >> 24; *enc->cur = digit + '0'; enc->cur += 1; } } else if (SvROK (sv)) @@ -648,6 +648,7 @@ { SV *sv = 0; int utf8 = 0; + char *dec_cur = dec->cur; do { @@ -656,33 +657,35 @@ do { - unsigned char ch = *(unsigned char *)dec->cur++; + unsigned char ch = *(unsigned char *)dec_cur++; if (expect_false (ch == '"')) { - --dec->cur; + --dec_cur; break; } else if (expect_false (ch == '\\')) { - switch (*dec->cur) + switch (*dec_cur) { case '\\': case '/': - case '"': *cur++ = *dec->cur++; break; + case '"': *cur++ = *dec_cur++; break; - case 'b': ++dec->cur; *cur++ = '\010'; break; - case 't': ++dec->cur; *cur++ = '\011'; break; - case 'n': ++dec->cur; *cur++ = '\012'; break; - case 'f': ++dec->cur; *cur++ = '\014'; break; - case 'r': ++dec->cur; *cur++ = '\015'; break; + case 'b': ++dec_cur; *cur++ = '\010'; break; + case 't': ++dec_cur; *cur++ = '\011'; break; + case 'n': ++dec_cur; *cur++ = '\012'; break; + case 'f': ++dec_cur; *cur++ = '\014'; break; + case 'r': ++dec_cur; *cur++ = '\015'; break; case 'u': { UV lo, hi; - ++dec->cur; + ++dec_cur; + dec->cur = dec_cur; hi = decode_4hex (dec); + dec_cur = dec->cur; if (hi == (UV)-1) goto fail; @@ -690,12 +693,14 @@ if (hi >= 0xd800) if (hi < 0xdc00) { - if (dec->cur [0] != '\\' || dec->cur [1] != 'u') + if (dec_cur [0] != '\\' || dec_cur [1] != 'u') ERR ("missing low surrogate character in surrogate pair"); - dec->cur += 2; + dec_cur += 2; + dec->cur = dec_cur; lo = decode_4hex (dec); + dec_cur = dec->cur; if (lo == (UV)-1) goto fail; @@ -719,7 +724,7 @@ break; default: - --dec->cur; + --dec_cur; ERR ("illegal backslash escape sequence in string"); } } @@ -730,21 +735,21 @@ STRLEN clen; UV uch; - --dec->cur; + --dec_cur; - uch = decode_utf8 (dec->cur, dec->end - dec->cur, &clen); + uch = decode_utf8 (dec_cur, dec->end - dec_cur, &clen); if (clen == (STRLEN)-1) ERR ("malformed UTF-8 character in JSON string"); do - *cur++ = *dec->cur++; + *cur++ = *dec_cur++; while (--clen); utf8 = 1; } else { - --dec->cur; + --dec_cur; if (!ch) ERR ("unexpected end of string while parsing JSON string"); @@ -767,9 +772,9 @@ sv = newSVpvn (buf, len); } } - while (*dec->cur != '"'); + while (*dec_cur != '"'); - ++dec->cur; + ++dec_cur; if (sv) { @@ -782,9 +787,11 @@ else sv = newSVpvn ("", 0); + dec->cur = dec_cur; return sv; fail: + dec->cur = dec_cur; return 0; }