summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNobuyoshi Nakada <nobu@ruby-lang.org>2011-07-08 06:39:42 +0900
committerFlorian Frank <flori@ping.de>2011-07-08 01:24:58 +0200
commit72b05a2bc42bc80c9f1b55948110a9a050c18ba8 (patch)
treee20552954bd28322be40548f6738b25bbcf8ea76
parentfa563e8f1665fe5f54d26ce4321ce9bd4786c1c3 (diff)
downloadjson-72b05a2bc42bc80c9f1b55948110a9a050c18ba8.tar.gz
no force_encoding
* ext/json/ext/parser/parser.rl (JSON_parse_string): no needs to use force_encoding.
-rw-r--r--ext/json/ext/parser/parser.c30
-rw-r--r--ext/json/ext/parser/parser.rl20
2 files changed, 15 insertions, 35 deletions
diff --git a/ext/json/ext/parser/parser.c b/ext/json/ext/parser/parser.c
index bb6c780..4910865 100644
--- a/ext/json/ext/parser/parser.c
+++ b/ext/json/ext/parser/parser.c
@@ -69,7 +69,7 @@ static int convert_UTF32_to_UTF8(char *buf, UTF32 ch)
#ifdef HAVE_RUBY_ENCODING_H
static VALUE CEncoding_ASCII_8BIT, CEncoding_UTF_8, CEncoding_UTF_16BE,
CEncoding_UTF_16LE, CEncoding_UTF_32BE, CEncoding_UTF_32LE;
-static ID i_encoding, i_encode, i_encode_bang, i_force_encoding;
+static ID i_encoding, i_encode;
#else
static ID i_iconv;
#endif
@@ -1575,21 +1575,13 @@ static VALUE convert_encoding(VALUE source)
VALUE encoding = rb_funcall(source, i_encoding, 0);
if (encoding == CEncoding_ASCII_8BIT) {
if (len >= 4 && ptr[0] == 0 && ptr[1] == 0 && ptr[2] == 0) {
- source = rb_str_dup(source);
- rb_funcall(source, i_force_encoding, 1, CEncoding_UTF_32BE);
- source = rb_funcall(source, i_encode_bang, 1, CEncoding_UTF_8);
+ source = rb_funcall(source, i_encode, 2, CEncoding_UTF_8, CEncoding_UTF_32BE);
} else if (len >= 4 && ptr[0] == 0 && ptr[2] == 0) {
- source = rb_str_dup(source);
- rb_funcall(source, i_force_encoding, 1, CEncoding_UTF_16BE);
- source = rb_funcall(source, i_encode_bang, 1, CEncoding_UTF_8);
+ source = rb_funcall(source, i_encode, 2, CEncoding_UTF_8, CEncoding_UTF_16BE);
} else if (len >= 4 && ptr[1] == 0 && ptr[2] == 0 && ptr[3] == 0) {
- source = rb_str_dup(source);
- rb_funcall(source, i_force_encoding, 1, CEncoding_UTF_32LE);
- source = rb_funcall(source, i_encode_bang, 1, CEncoding_UTF_8);
+ source = rb_funcall(source, i_encode, 2, CEncoding_UTF_8, CEncoding_UTF_32LE);
} else if (len >= 4 && ptr[1] == 0 && ptr[3] == 0) {
- source = rb_str_dup(source);
- rb_funcall(source, i_force_encoding, 1, CEncoding_UTF_16LE);
- source = rb_funcall(source, i_encode_bang, 1, CEncoding_UTF_8);
+ source = rb_funcall(source, i_encode, 2, CEncoding_UTF_8, CEncoding_UTF_16LE);
} else {
FORCE_UTF8(source);
}
@@ -1741,16 +1733,16 @@ static VALUE cParser_parse(VALUE self)
GET_PARSER;
-#line 1745 "parser.c"
+#line 1737 "parser.c"
{
cs = JSON_start;
}
-#line 742 "parser.rl"
+#line 734 "parser.rl"
p = json->source;
pe = p + json->len;
-#line 1754 "parser.c"
+#line 1746 "parser.c"
{
if ( p == pe )
goto _test_eof;
@@ -1827,7 +1819,7 @@ st10:
if ( ++p == pe )
goto _test_eof10;
case 10:
-#line 1831 "parser.c"
+#line 1823 "parser.c"
switch( (*p) ) {
case 13: goto st10;
case 32: goto st10;
@@ -1884,7 +1876,7 @@ case 9:
_out: {}
}
-#line 745 "parser.rl"
+#line 737 "parser.rl"
if (cs >= JSON_first_final && p == pe) {
return result;
@@ -1975,8 +1967,6 @@ void Init_parser()
CEncoding_ASCII_8BIT = rb_funcall(rb_path2class("Encoding"), rb_intern("find"), 1, rb_str_new2("ascii-8bit"));
i_encoding = rb_intern("encoding");
i_encode = rb_intern("encode");
- i_encode_bang = rb_intern("encode!");
- i_force_encoding = rb_intern("force_encoding");
#else
i_iconv = rb_intern("iconv");
#endif
diff --git a/ext/json/ext/parser/parser.rl b/ext/json/ext/parser/parser.rl
index 44ddfa6..b18f06f 100644
--- a/ext/json/ext/parser/parser.rl
+++ b/ext/json/ext/parser/parser.rl
@@ -67,7 +67,7 @@ static int convert_UTF32_to_UTF8(char *buf, UTF32 ch)
#ifdef HAVE_RUBY_ENCODING_H
static VALUE CEncoding_ASCII_8BIT, CEncoding_UTF_8, CEncoding_UTF_16BE,
CEncoding_UTF_16LE, CEncoding_UTF_32BE, CEncoding_UTF_32LE;
-static ID i_encoding, i_encode, i_encode_bang, i_force_encoding;
+static ID i_encoding, i_encode;
#else
static ID i_iconv;
#endif
@@ -573,21 +573,13 @@ static VALUE convert_encoding(VALUE source)
VALUE encoding = rb_funcall(source, i_encoding, 0);
if (encoding == CEncoding_ASCII_8BIT) {
if (len >= 4 && ptr[0] == 0 && ptr[1] == 0 && ptr[2] == 0) {
- source = rb_str_dup(source);
- rb_funcall(source, i_force_encoding, 1, CEncoding_UTF_32BE);
- source = rb_funcall(source, i_encode_bang, 1, CEncoding_UTF_8);
+ source = rb_funcall(source, i_encode, 2, CEncoding_UTF_8, CEncoding_UTF_32BE);
} else if (len >= 4 && ptr[0] == 0 && ptr[2] == 0) {
- source = rb_str_dup(source);
- rb_funcall(source, i_force_encoding, 1, CEncoding_UTF_16BE);
- source = rb_funcall(source, i_encode_bang, 1, CEncoding_UTF_8);
+ source = rb_funcall(source, i_encode, 2, CEncoding_UTF_8, CEncoding_UTF_16BE);
} else if (len >= 4 && ptr[1] == 0 && ptr[2] == 0 && ptr[3] == 0) {
- source = rb_str_dup(source);
- rb_funcall(source, i_force_encoding, 1, CEncoding_UTF_32LE);
- source = rb_funcall(source, i_encode_bang, 1, CEncoding_UTF_8);
+ source = rb_funcall(source, i_encode, 2, CEncoding_UTF_8, CEncoding_UTF_32LE);
} else if (len >= 4 && ptr[1] == 0 && ptr[3] == 0) {
- source = rb_str_dup(source);
- rb_funcall(source, i_force_encoding, 1, CEncoding_UTF_16LE);
- source = rb_funcall(source, i_encode_bang, 1, CEncoding_UTF_8);
+ source = rb_funcall(source, i_encode, 2, CEncoding_UTF_8, CEncoding_UTF_16LE);
} else {
FORCE_UTF8(source);
}
@@ -832,8 +824,6 @@ void Init_parser()
CEncoding_ASCII_8BIT = rb_funcall(rb_path2class("Encoding"), rb_intern("find"), 1, rb_str_new2("ascii-8bit"));
i_encoding = rb_intern("encoding");
i_encode = rb_intern("encode");
- i_encode_bang = rb_intern("encode!");
- i_force_encoding = rb_intern("force_encoding");
#else
i_iconv = rb_intern("iconv");
#endif