From b16fd08622a5b79259c7af22ef2ce8b06652d79e Mon Sep 17 00:00:00 2001 From: nobu Date: Fri, 8 Jul 2011 07:39:09 +0000 Subject: [PATCH] * ext/json/parser/parser.rl (convert_encoding): no needs to use force_encoding. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@32457 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- ChangeLog | 5 +++++ ext/json/parser/parser.c | 30 ++++++++++-------------------- ext/json/parser/parser.rl | 20 +++++--------------- 3 files changed, 20 insertions(+), 35 deletions(-) diff --git a/ChangeLog b/ChangeLog index 08d9cad408..81b3548b73 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +Fri Jul 8 16:39:03 2011 Nobuyoshi Nakada + + * ext/json/parser/parser.rl (convert_encoding): no needs to use + force_encoding. + Fri Jul 8 15:53:31 2011 Nobuyoshi Nakada * error.c (rb_bug): get rid of segfault after all threads diff --git a/ext/json/parser/parser.c b/ext/json/parser/parser.c index 85094b7301..817597ede4 100644 --- a/ext/json/parser/parser.c +++ b/ext/json/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 @@ -1543,21 +1543,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); } @@ -1702,16 +1694,16 @@ static VALUE cParser_parse(VALUE self) GET_PARSER; -#line 1706 "parser.c" +#line 1698 "parser.c" { cs = JSON_start; } -#line 703 "parser.rl" +#line 695 "parser.rl" p = json->source; pe = p + json->len; -#line 1715 "parser.c" +#line 1707 "parser.c" { if ( p == pe ) goto _test_eof; @@ -1788,7 +1780,7 @@ st10: if ( ++p == pe ) goto _test_eof10; case 10: -#line 1792 "parser.c" +#line 1784 "parser.c" switch( (*p) ) { case 13: goto st10; case 32: goto st10; @@ -1845,7 +1837,7 @@ case 9: _out: {} } -#line 706 "parser.rl" +#line 698 "parser.rl" if (cs >= JSON_first_final && p == pe) { return result; @@ -1931,8 +1923,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/parser/parser.rl b/ext/json/parser/parser.rl index 278386432b..abd056f18c 100644 --- a/ext/json/parser/parser.rl +++ b/ext/json/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 @@ -541,21 +541,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); } @@ -788,8 +780,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