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

Comparing JSON-XS/XS.xs (file contents):
Revision 1.45 by root, Mon Jun 25 06:57:42 2007 UTC vs.
Revision 1.46 by root, Mon Jun 25 22:11:39 2007 UTC

1023 if (*dec->cur == '}') 1023 if (*dec->cur == '}')
1024 ++dec->cur; 1024 ++dec->cur;
1025 else 1025 else
1026 for (;;) 1026 for (;;)
1027 { 1027 {
1028 SV *key, *value;
1029
1030 decode_ws (dec); EXPECT_CH ('"'); 1028 decode_ws (dec); EXPECT_CH ('"');
1031 1029
1032 key = decode_str (dec); 1030 // heuristic: assume that
1033 if (!key) 1031 // a) decode_str + hv_store_ent are abysmally slow
1034 goto fail; 1032 // b) most hash keys are short, simple ascii text
1033 // so try to "fast-match" such strings to avoid
1034 // the overhead of hv_store_ent.
1035 {
1036 SV *value;
1037 char *p = dec->cur;
1038 char *e = p + 24; // only try up to 24 bytes
1035 1039
1036 decode_ws (dec); EXPECT_CH (':'); 1040 for (;;)
1037
1038 value = decode_sv (dec);
1039 if (!value)
1040 { 1041 {
1042 if (p == e || *p < 0x20 || *p >= 0x80 || *p == '\\')
1043 {
1044 // slow path, back up and use decode_str
1045 SV *key = decode_str (dec);
1046 if (!key)
1047 goto fail;
1048
1049 decode_ws (dec); EXPECT_CH (':');
1050
1051 value = decode_sv (dec);
1052 if (!value)
1053 {
1054 SvREFCNT_dec (key);
1055 goto fail;
1056 }
1057
1058 hv_store_ent (hv, key, value, 0);
1041 SvREFCNT_dec (key); 1059 SvREFCNT_dec (key);
1060
1061 break;
1062 }
1063 else if (*p == '"')
1064 {
1065 // fast path, got a simple key
1066 char *key = dec->cur;
1067 int len = p - key;
1068 dec->cur = p + 1;
1069
1070 decode_ws (dec); EXPECT_CH (':');
1071
1072 value = decode_sv (dec);
1073 if (!value)
1042 goto fail; 1074 goto fail;
1075
1076 hv_store (hv, key, len, value, 0);
1077
1078 break;
1079 }
1080
1081 ++p;
1043 } 1082 }
1044 1083 }
1045 hv_store_ent (hv, key, value, 0);
1046 SvREFCNT_dec (key);
1047 1084
1048 decode_ws (dec); 1085 decode_ws (dec);
1049 1086
1050 if (*dec->cur == '}') 1087 if (*dec->cur == '}')
1051 { 1088 {

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines