[前][次][番号順一覧][スレッド一覧]

ruby-changes:38259

From: nobu <ko1@a...>
Date: Sat, 18 Apr 2015 15:19:03 +0900 (JST)
Subject: [ruby-changes:38259] nobu:r50340 (trunk): parser.rl: use rb_encoding

nobu	2015-04-18 15:18:50 +0900 (Sat, 18 Apr 2015)

  New Revision: 50340

  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=50340

  Log:
    parser.rl: use rb_encoding
    
    * ext/json/parser/parser.rl (convert_encoding): use rb_encoding
      functions to compare and convert encodings.

  Modified files:
    trunk/ext/json/parser/parser.c
    trunk/ext/json/parser/parser.rl
Index: ext/json/parser/parser.rl
===================================================================
--- ext/json/parser/parser.rl	(revision 50339)
+++ ext/json/parser/parser.rl	(revision 50340)
@@ -66,9 +66,7 @@ static int convert_UTF32_to_UTF8(char *b https://github.com/ruby/ruby/blob/trunk/ext/json/parser/parser.rl#L66
 }
 
 #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;
+static rb_encoding *UTF_16BE, *UTF_16LE, *UTF_32BE, *UTF_32LE;
 #else
 static ID i_iconv;
 #endif
@@ -557,22 +555,22 @@ static VALUE convert_encoding(VALUE sour https://github.com/ruby/ruby/blob/trunk/ext/json/parser/parser.rl#L555
     }
 #ifdef HAVE_RUBY_ENCODING_H
     {
-        VALUE encoding = rb_funcall(source, i_encoding, 0);
-        if (encoding == CEncoding_ASCII_8BIT) {
+        rb_encoding *enc = rb_enc_get(source);
+        if (enc == rb_ascii8bit_encoding()) {
             if (len >= 4 &&  ptr[0] == 0 && ptr[1] == 0 && ptr[2] == 0) {
-                source = rb_funcall(source, i_encode, 2, CEncoding_UTF_8, CEncoding_UTF_32BE);
+                source = rb_str_conv_enc(source, UTF_32BE, rb_utf8_encoding());
             } else if (len >= 4 && ptr[0] == 0 && ptr[2] == 0) {
-                source = rb_funcall(source, i_encode, 2, CEncoding_UTF_8, CEncoding_UTF_16BE);
+                source = rb_str_conv_enc(source, UTF_16BE, rb_utf8_encoding());
             } else if (len >= 4 && ptr[1] == 0 && ptr[2] == 0 && ptr[3] == 0) {
-                source = rb_funcall(source, i_encode, 2, CEncoding_UTF_8, CEncoding_UTF_32LE);
+                source = rb_str_conv_enc(source, UTF_32LE, rb_utf8_encoding());
             } else if (len >= 4 && ptr[1] == 0 && ptr[3] == 0) {
-                source = rb_funcall(source, i_encode, 2, CEncoding_UTF_8, CEncoding_UTF_16LE);
+                source = rb_str_conv_enc(source, UTF_16LE, rb_utf8_encoding());
             } else {
                 source = rb_str_dup(source);
                 FORCE_UTF8(source);
             }
         } else {
-            source = rb_funcall(source, i_encode, 1, CEncoding_UTF_8);
+            source = rb_str_conv_enc(source, NULL, rb_utf8_encoding());
         }
     }
 #else
@@ -922,14 +920,10 @@ void Init_parser(void) https://github.com/ruby/ruby/blob/trunk/ext/json/parser/parser.rl#L920
     i_aref = rb_intern("[]");
     i_leftshift = rb_intern("<<");
 #ifdef HAVE_RUBY_ENCODING_H
-    CEncoding_UTF_8 = rb_funcall(rb_path2class("Encoding"), rb_intern("find"), 1, rb_str_new2("utf-8"));
-    CEncoding_UTF_16BE = rb_funcall(rb_path2class("Encoding"), rb_intern("find"), 1, rb_str_new2("utf-16be"));
-    CEncoding_UTF_16LE = rb_funcall(rb_path2class("Encoding"), rb_intern("find"), 1, rb_str_new2("utf-16le"));
-    CEncoding_UTF_32BE = rb_funcall(rb_path2class("Encoding"), rb_intern("find"), 1, rb_str_new2("utf-32be"));
-    CEncoding_UTF_32LE = rb_funcall(rb_path2class("Encoding"), rb_intern("find"), 1, rb_str_new2("utf-32le"));
-    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");
+    UTF_16BE = rb_enc_find("utf-16be");
+    UTF_16LE = rb_enc_find("utf-16le");
+    UTF_32BE = rb_enc_find("utf-32be");
+    UTF_32LE = rb_enc_find("utf-32le");
 #else
     i_iconv = rb_intern("iconv");
 #endif
Index: ext/json/parser/parser.c
===================================================================
--- ext/json/parser/parser.c	(revision 50339)
+++ ext/json/parser/parser.c	(revision 50340)
@@ -3,6 +3,13 @@ https://github.com/ruby/ruby/blob/trunk/ext/json/parser/parser.c#L3
 #include "../fbuffer/fbuffer.h"
 #include "parser.h"
 
+#ifdef HAVE_RB_ENC_RAISE
+# define EXC_ENCODING rb_utf8_encoding(),
+#else
+# define rb_enc_raise rb_raise
+# define EXC_ENCODING /* nothing */
+#endif
+
 /* unicode */
 
 static const char digit_values[256] = {
@@ -68,9 +75,7 @@ static int convert_UTF32_to_UTF8(char *b https://github.com/ruby/ruby/blob/trunk/ext/json/parser/parser.c#L75
 }
 
 #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;
+static rb_encoding *UTF_16BE, *UTF_16LE, *UTF_32BE, *UTF_32LE;
 #else
 static ID i_iconv;
 #endif
@@ -84,11 +89,11 @@ static ID i_json_creatable_p, i_json_cre https://github.com/ruby/ruby/blob/trunk/ext/json/parser/parser.c#L89
           i_match_string, i_aset, i_aref, i_leftshift;
 
 
-#line 110 "parser.rl"
+#line 115 "parser.rl"
 
 
 
-#line 92 "parser.c"
+#line 97 "parser.c"
 enum {JSON_object_start = 1};
 enum {JSON_object_first_final = 27};
 enum {JSON_object_error = 0};
@@ -96,7 +101,7 @@ enum {JSON_object_error = 0}; https://github.com/ruby/ruby/blob/trunk/ext/json/parser/parser.c#L101
 enum {JSON_object_en_main = 1};
 
 
-#line 151 "parser.rl"
+#line 156 "parser.rl"
 
 
 static char *JSON_parse_object(JSON_Parser *json, char *p, char *pe, VALUE *result)
@@ -112,14 +117,14 @@ static char *JSON_parse_object(JSON_Pars https://github.com/ruby/ruby/blob/trunk/ext/json/parser/parser.c#L117
     *result = NIL_P(object_class) ? rb_hash_new() : rb_class_new_instance(0, 0, object_class);
 
 
-#line 116 "parser.c"
+#line 121 "parser.c"
 	{
 	cs = JSON_object_start;
 	}
 
-#line 166 "parser.rl"
+#line 171 "parser.rl"
 
-#line 123 "parser.c"
+#line 128 "parser.c"
 	{
 	if ( p == pe )
 		goto _test_eof;
@@ -147,7 +152,7 @@ case 2: https://github.com/ruby/ruby/blob/trunk/ext/json/parser/parser.c#L152
 		goto st2;
 	goto st0;
 tr2:
-#line 133 "parser.rl"
+#line 138 "parser.rl"
 	{
         char *np;
         json->parsing_name = 1;
@@ -160,7 +165,7 @@ st3: https://github.com/ruby/ruby/blob/trunk/ext/json/parser/parser.c#L165
 	if ( ++p == pe )
 		goto _test_eof3;
 case 3:
-#line 164 "parser.c"
+#line 169 "parser.c"
 	switch( (*p) ) {
 		case 13: goto st3;
 		case 32: goto st3;
@@ -227,7 +232,7 @@ case 8: https://github.com/ruby/ruby/blob/trunk/ext/json/parser/parser.c#L232
 		goto st8;
 	goto st0;
 tr11:
-#line 118 "parser.rl"
+#line 123 "parser.rl"
 	{
         VALUE v = Qnil;
         char *np = JSON_parse_value(json, p, pe, &v);
@@ -247,7 +252,7 @@ st9: https://github.com/ruby/ruby/blob/trunk/ext/json/parser/parser.c#L252
 	if ( ++p == pe )
 		goto _test_eof9;
 case 9:
-#line 251 "parser.c"
+#line 256 "parser.c"
 	switch( (*p) ) {
 		case 13: goto st9;
 		case 32: goto st9;
@@ -336,14 +341,14 @@ case 18: https://github.com/ruby/ruby/blob/trunk/ext/json/parser/parser.c#L341
 		goto st9;
 	goto st18;
 tr4:
-#line 141 "parser.rl"
+#line 146 "parser.rl"
 	{ p--; {p++; cs = 27; goto _out;} }
 	goto st27;
 st27:
 	if ( ++p == pe )
 		goto _test_eof27;
 case 27:
-#line 347 "parser.c"
+#line 352 "parser.c"
 	goto st0;
 st19:
 	if ( ++p == pe )
@@ -441,7 +446,7 @@ case 26: https://github.com/ruby/ruby/blob/trunk/ext/json/parser/parser.c#L446
 	_out: {}
 	}
 
-#line 167 "parser.rl"
+#line 172 "parser.rl"
 
     if (cs >= JSON_object_first_final) {
         if (json->create_additions) {
@@ -466,7 +471,7 @@ case 26: https://github.com/ruby/ruby/blob/trunk/ext/json/parser/parser.c#L471
 
 
 
-#line 470 "parser.c"
+#line 475 "parser.c"
 enum {JSON_value_start = 1};
 enum {JSON_value_first_final = 21};
 enum {JSON_value_error = 0};
@@ -474,7 +479,7 @@ enum {JSON_value_error = 0}; https://github.com/ruby/ruby/blob/trunk/ext/json/parser/parser.c#L479
 enum {JSON_value_en_main = 1};
 
 
-#line 271 "parser.rl"
+#line 276 "parser.rl"
 
 
 static char *JSON_parse_value(JSON_Parser *json, char *p, char *pe, VALUE *result)
@@ -482,14 +487,14 @@ static char *JSON_parse_value(JSON_Parse https://github.com/ruby/ruby/blob/trunk/ext/json/parser/parser.c#L487
     int cs = EVIL;
 
 
-#line 486 "parser.c"
+#line 491 "parser.c"
 	{
 	cs = JSON_value_start;
 	}
 
-#line 278 "parser.rl"
+#line 283 "parser.rl"
 
-#line 493 "parser.c"
+#line 498 "parser.c"
 	{
 	if ( p == pe )
 		goto _test_eof;
@@ -514,14 +519,14 @@ st0: https://github.com/ruby/ruby/blob/trunk/ext/json/parser/parser.c#L519
 cs = 0;
 	goto _out;
 tr0:
-#line 219 "parser.rl"
+#line 224 "parser.rl"
 	{
         char *np = JSON_parse_string(json, p, pe, result);
         if (np == NULL) { p--; {p++; cs = 21; goto _out;} } else {p = (( np))-1;}
     }
 	goto st21;
 tr2:
-#line 224 "parser.rl"
+#line 229 "parser.rl"
 	{
         char *np;
         if(pe > p + 9 - json->quirks_mode && !strncmp(MinusInfinity, p, 9)) {
@@ -530,7 +535,7 @@ tr2: https://github.com/ruby/ruby/blob/trunk/ext/json/parser/parser.c#L535
                 {p = (( p + 10))-1;}
                 p--; {p++; cs = 21; goto _out;}
             } else {
-                rb_raise(eParserError, "%u: unexpected token at '%s'", __LINE__, p);
+                rb_enc_raise(EXC_ENCODING eParserError, "%u: unexpected token at '%s'", __LINE__, p);
             }
         }
         np = JSON_parse_float(json, p, pe, result);
@@ -541,7 +546,7 @@ tr2: https://github.com/ruby/ruby/blob/trunk/ext/json/parser/parser.c#L546
     }
 	goto st21;
 tr5:
-#line 242 "parser.rl"
+#line 247 "parser.rl"
 	{
         char *np;
         json->current_nesting++;
@@ -551,7 +556,7 @@ tr5: https://github.com/ruby/ruby/blob/trunk/ext/json/parser/parser.c#L556
     }
 	goto st21;
 tr9:
-#line 250 "parser.rl"
+#line 255 "parser.rl"
 	{
         char *np;
         json->current_nesting++;
@@ -561,39 +566,39 @@ tr9: https://github.com/ruby/ruby/blob/trunk/ext/json/parser/parser.c#L566
     }
 	goto st21;
 tr16:
-#line 212 "parser.rl"
+#line 217 "parser.rl"
 	{
         if (json->allow_nan) {
             *result = CInfinity;
         } else {
-            rb_raise(eParserError, "%u: unexpected token at '%s'", __LINE__, p - 8);
+            rb_enc_raise(EXC_ENCODING eParserError, "%u: unexpected token at '%s'", __LINE__, p - 8);
         }
     }
 	goto st21;
 tr18:
-#line 205 "parser.rl"
+#line 210 "parser.rl"
 	{
         if (json->allow_nan) {
             *result = CNaN;
         } else {
-            rb_raise(eParserError, "%u: unexpected token at '%s'", __LINE__, p - 2);
+            rb_enc_raise(EXC_ENCODING eParserError, "%u: unexpected token at '%s'", __LINE__, p - 2);
         }
     }
 	goto st21;
 tr22:
-#line 199 "parser.rl"
+#line 204 "parser.rl"
 	{
         *result = Qfalse;
     }
 	goto st21;
 tr25:
-#line 196 "parser.rl"
+#line 201 "parser.rl"
 	{
         *result = Qnil;
     }
 	goto st21;
 tr28:
-#line 202 "parser.rl"
+#line 207 "parser.rl"
 	{
         *result = Qtrue;
     }
@@ -602,9 +607,9 @@ st21: https://github.com/ruby/ruby/blob/trunk/ext/json/parser/parser.c#L607
 	if ( ++p == pe )
 		goto _test_eof21;
 case 21:
-#line 258 "parser.rl"
+#line 263 "parser.rl"
 	{ p--; {p++; cs = 21; goto _out;} }
-#line 608 "parser.c"
+#line 613 "parser.c"
 	goto st0;
 st2:
 	if ( ++p == pe )
@@ -765,7 +770,7 @@ case 20: https://github.com/ruby/ruby/blob/trunk/ext/json/parser/parser.c#L770
 	_out: {}
 	}
 
-#line 279 "parser.rl"
+#line 284 "parser.rl"
 
     if (cs >= JSON_value_first_final) {
         return p;
@@ -775,7 +780,7 @@ case 20: https://github.com/ruby/ruby/blob/trunk/ext/json/parser/parser.c#L780
 }
 
 
-#line 779 "parser.c"
+#line 784 "parser.c"
 enum {JSON_integer_start = 1};
 enum {JSON_integer_first_final = 3};
 enum {JSON_integer_error = 0};
@@ -783,7 +788,7 @@ enum {JSON_integer_error = 0}; https://github.com/ruby/ruby/blob/trunk/ext/json/parser/parser.c#L788
 enum {JSON_integer_en_main = 1};
 
 
-#line 295 "parser.rl"
+#line 300 "parser.rl"
 
 
 static char *JSON_parse_integer(JSON_Parser *json, char *p, char *pe, VALUE *result)
@@ -791,15 +796,15 @@ static char *JSON_parse_integer(JSON_Par https://github.com/ruby/ruby/blob/trunk/ext/json/parser/parser.c#L796
     int cs = EVIL;
 
 
-#line 795 "parser.c"
+#line 800 "parser.c"
 	{
 	cs = JSON_integer_start;
 	}
 
-#line 302 "parser.rl"
+#line 307 "parser.rl"
     json->memo = p;
 
-#line 803 "parser.c"
+#line 808 "parser.c"
 	{
 	if ( p == pe )
 		goto _test_eof;
@@ -833,14 +838,14 @@ case 3: https://github.com/ruby/ruby/blob/trunk/ext/json/parser/parser.c#L838
 		goto st0;
 	goto tr4;
 tr4:
-#line 292 "parser.rl"
+#line 297 "parser.rl"
 	{ p--; {p++; cs = 4; goto _out;} }
 	goto st4;
 st4:
 	if ( ++p == pe )
 		goto _test_eof4;
 case 4:
-#line 844 "parser.c"
+#line 849 "parser.c"
 	goto st0;
 st5:
 	if ( ++p == pe )
@@ -859,7 +864,7 @@ case 5: https://github.com/ruby/ruby/blob/trunk/ext/json/parser/parser.c#L864
 	_out: {}
 	}
 
-#line 304 "parser.rl"
+#line 309 "parser.rl"
 
     if (cs >= JSON_integer_first_final) {
         long len = p - json->memo;
@@ -874,7 +879,7 @@ case 5: https://github.com/ruby/ruby/blob/trunk/ext/json/parser/parser.c#L879
 }
 
 
-#line 878 "parser.c"
+#line 883 "parser.c"
 enum {JSON_float_start = 1};
 enum {JSON_float_first_final = 8};
 enum {JSON_float_error = 0};
@@ -882,7 +887,7 @@ enum {JSON_float_error = 0}; https://github.com/ruby/ruby/blob/trunk/ext/json/parser/parser.c#L887
 enum {JSON_float_en_main = 1};
 
 
-#line 329 "parser.rl"
+#line 334 "parser.rl"
 
 
 static char *JSON_parse_float(JSON_Parser *json, char *p, char *pe, VALUE *result)
@@ -890,15 +895,15 @@ static char *JSON_parse_float(JSON_Parse https://github.com/ruby/ruby/blob/trunk/ext/json/parser/parser.c#L895
     int cs = EVIL;
 
 
-#line 894 "parser.c"
+#line 899 "parser.c"
 	{
 	cs = JSON_float_start;
 	}
 
-#line 336 "parser.rl"
+#line 341 "parser.rl"
     json->memo = p;
 
-#line 902 "parser.c"
+#line 907 "parser.c"
 	{
 	if ( p == pe )
 		goto _test_eof;
@@ -956,14 +961,14 @@ case 8: https://github.com/ruby/ruby/blob/trunk/ext/json/parser/parser.c#L961
 		goto st0;
 	goto tr9;
 tr9:
-#line 323 "parser.rl"
+#line 328 "parser.rl"
 	{ p--; {p++; cs = 9; goto _out;} }
 	goto st9;
 st9:
 	if ( ++p == pe )
 		goto _test_eof9;
 case 9:
-#line 967 "parser.c"
+#line 972 "parser.c"
 	goto st0;
 st5:
 	if ( ++p == pe )
@@ -1024,7 +1029,7 @@ case 7: https://github.com/ruby/ruby/blob/trunk/ext/json/parser/parser.c#L1029
 	_out: {}
 	}
 
-#line 338 "parser.rl"
+#line 343 "parser.rl"
 
     if (cs >= JSON_float_first_final) {
         long len = p - json->memo;
@@ -1040,7 +1045,7 @@ case 7: https://github.com/ruby/ruby/blob/trunk/ext/json/parser/parser.c#L1045
 
 
 
-#line 1044 "parser.c"
+#line 1049 "parser.c"
 enum {JSON_array_start = 1};
 enum {JSON_array_first_final = 17};
 enum {JSON_array_error = 0};
@@ -1048,7 +1053,7 @@ enum {JSON_array_error = 0}; https://github.com/ruby/ruby/blob/trunk/ext/json/parser/parser.c#L1053
 enum {JSON_array_en_main = 1};
 
 
-#line 381 "parser.rl"
+#line 386 "parser.rl"
 
 
 static char *JSON_parse_array(JSON_Parser *json, char *p, char *pe, VALUE *result)
@@ -1062,14 +1067,14 @@ static char *JSON_parse_array(JSON_Parse https://github.com/ruby/ruby/blob/trunk/ext/json/parser/parser.c#L1067
     *result = NIL_P(array_class) ? rb_ary_new() : rb_class_new_instance(0, 0, array_class);
 
 
-#line 1066 "parser.c"
+#line 1071 "parser.c"
 	{
 	cs = JSON_array_start;
 	}
 
-#line 394 "parser.rl"
+#line 399 "parser.rl"
 
-#line 1073 "parser.c"
+#line 1078 "parser.c"
 	{
 	if ( p == pe )
 		goto _test_eof;
@@ -1108,7 +1113,7 @@ case 2: https://github.com/ruby/ruby/blob/trunk/ext/json/parser/parser.c#L1113
 		goto st2;
 	goto st0;
 tr2:
-#line 358 "parser.rl"
+#line 363 "parser.rl"
 	{
         VALUE v = Qnil;
         char *np = JSON_parse_value(json, p, pe, &v);
@@ -1128,7 +1133,7 @@ st3: https://github.com/ruby/ruby/blob/trunk/ext/json/parser/parser.c#L1133
 	if ( ++p == pe )
 		goto _test_eof3;
 case 3:
-#line 1132 "parser.c"
+#line 1137 "parser.c"
 	switch( (*p) ) {
 		case 13: goto st3;
 		case 32: goto st3;
@@ -1228,14 +1233,14 @@ case 12: https://github.com/ruby/ruby/blob/trunk/ext/json/parser/parser.c#L1233
 		goto st3;
 	goto st12;
 tr4:
-#line 373 "parser.rl"
+#line 378 "parser.rl"
 	{ p--; {p++; cs = 17; goto _out;} }
 	goto st17;
 st17:
 	if ( ++p == pe )
 		goto _test_eof17;
 case 17:
-#line 1239 "parser.c"
+#line 1244 "parser.c"
 	goto st0;
 st13:
 	if ( ++p == pe )
@@ -1291,12 +1296,12 @@ case 16: https://github.com/ruby/ruby/blob/trunk/ext/json/parser/parser.c#L1296
 	_out: {}
 	}
 
-#line 395 "parser.rl"
+#line 400 "parser.rl"
 
     if(cs >= JSON_array_first_final) {
         return p + 1;
     } else {
-        rb_raise(eParserError, "%u: unexpected token at '%s'", __LINE__, p);
+        rb_enc_raise(EXC_ENCODING eParserError, "%u: unexpected token at '%s'", __LINE__, p);
         return NULL;
     }
 }
@@ -1372,7 +1377,7 @@ static VALUE json_string_unescape(VALUE https://github.com/ruby/ruby/blob/trunk/ext/json/parser/parser.c#L1377
 }
 
 
-#line 1376 "parser.c"
+#line 1381 "parser.c"
 enum {JSON_string_start = 1};
 enum {JSON_string_first_final = 8};
 enum {JSON_string_error = 0};
@@ -1380,7 +1385,7 @@ enum {JSON_string_error = 0}; https://github.com/ruby/ruby/blob/trunk/ext/json/parser/parser.c#L1385
 enum {JSON_string_en_main = 1};
 
 
-#line 494 "parser.rl"
+#line 499 "parser.rl"
 
 
 static int
@@ -1402,15 +1407,15 @@ static char *JSON_parse_string(JSON_Pars https://github.com/ruby/ruby/blob/trunk/ext/json/parser/parser.c#L1407
 
     *result = rb_str_buf_new(0);
 
-#line 1406 "parser.c"
+#line 1411 "parser.c"
 	{
 	cs = JSON_string_start;
 	}
 
-#line 515 "parser.rl"
+#line 520 "parser.rl"
     json->memo = p;
 
-#line 1414 "parser.c"
+#line 1419 "parser.c"
 	{
 	if ( p == pe )
 		goto _test_eof;
@@ -1435,7 +1440,7 @@ case 2: https://github.com/ruby/ruby/blob/trunk/ext/json/parser/parser.c#L1440
 		goto st0;
 	goto st2;
 tr2:
-#line 480 "parser.rl"
+#line 485 "parser.rl"
 	{
         *result = json_string_unescape(*result, json->memo + 1, p);
         if (NIL_P(*result)) {
@@ -1446,14 +1451,14 @@ tr2: https://github.com/ruby/ruby/blob/trunk/ext/json/parser/parser.c#L1451
             {p = (( p + 1))-1;}
         }
     }
-#line 491 "parser.rl"
+#line 496 "parser.rl"
 	{ p--; {p++; cs = 8; goto _out;} }
 	goto st8;
 st8:
 	if ( ++p == pe )
 		goto _test_eof8;
 case 8:
-#line 1457 "parser.c"
+#line 1462 "parser.c"
 	goto st0;
 st3:
 	if ( ++p == pe )
@@ -1529,7 +1534,7 @@ case 7: https://github.com/ruby/ruby/blob/trunk/ext/json/parser/parser.c#L1534
 	_out: {}
 	}
 
-#line 517 "parser.rl"
+#line 522 "parser.rl"
 
     if (json->create_additions && RTEST(match_string = json->match_string)) {
           VALUE klass;
@@ -1573,22 +1578,22 @@ static VALUE convert_encoding(VALUE sour https://github.com/ruby/ruby/blob/trunk/ext/json/parser/parser.c#L1578
     }
 #ifdef HAVE_RUBY_ENCODING_H
     {
-        VALUE encoding = rb_funcall(source, i_encoding, 0);
-        if (encoding == CEncoding_ASCII_8BIT) {
+        rb_encoding *enc = rb_enc_get(source);
+        if (enc == rb_ascii8bit_encoding()) {
             if (len >= 4 &&  ptr[0] == 0 && ptr[1] == 0 && ptr[2] == 0) {
-                source = rb_funcall(source, i_encode, 2, CEncoding_UTF_8, CEncoding_UTF_32BE);
+                source = rb_str_conv_enc(source, UTF_32BE, rb_utf8_encoding());
             } else if (len >= 4 && ptr[0] == 0 && ptr[2] == 0) {
-                source = rb_funcall(source, i_encode, 2, CEncoding_UTF_8, CEncoding_UTF_16BE);
+                source = rb_str_conv_enc(source, UTF_16BE, rb_utf8_encoding());
             } else if (len >= 4 && ptr[1] == 0 && ptr[2] == 0 && ptr[3] == 0) {
-                source = rb_funcall(source, i_encode, 2, CEncoding_UTF_8, CEncoding_UTF_32LE);
+                source = rb_str_conv_enc(source, UTF_32LE, rb_utf8_encoding());
             } else if (len >= 4 && ptr[1] == 0 && ptr[3] == 0) {
-                source = rb_funcall(source, i_encode, 2, CEncoding_UTF_8, CEncoding_UTF_16LE);
+                source = rb_str_conv_enc(source, UTF_16LE, rb_utf8_encoding());
             } else {
                 source = rb_str_dup(source);
                 FORCE_UTF8(source);
             }
         } else {
-            source = rb_funcall(source, i_encode, 1, CEnco (... truncated)

--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]