@@ -742,17 +742,19 @@ static void generate_json_array(FBuffer *buffer, VALUE Vstate, JSON_Generator_St
742
742
fbuffer_append_char (buffer , ']' );
743
743
}
744
744
745
- static int enc_utf8_compatible_p (rb_encoding * enc )
745
+ static int usascii_encindex , utf8_encindex ;
746
+
747
+ static int enc_utf8_compatible_p (int enc_idx )
746
748
{
747
- if (enc == rb_usascii_encoding () ) return 1 ;
748
- if (enc == rb_utf8_encoding () ) return 1 ;
749
+ if (enc_idx == usascii_encindex ) return 1 ;
750
+ if (enc_idx == utf8_encindex ) return 1 ;
749
751
return 0 ;
750
752
}
751
753
752
754
static void generate_json_string (FBuffer * buffer , VALUE Vstate , JSON_Generator_State * state , VALUE obj )
753
755
{
754
756
fbuffer_append_char (buffer , '"' );
755
- if (!enc_utf8_compatible_p (rb_enc_get (obj ))) {
757
+ if (!enc_utf8_compatible_p (RB_ENCODING_GET (obj ))) {
756
758
obj = rb_str_export_to_enc (obj , rb_utf8_encoding ());
757
759
}
758
760
convert_UTF8_to_JSON (buffer , obj , state -> ascii_only , state -> script_safe );
@@ -1479,4 +1481,7 @@ void Init_generator(void)
1479
1481
i_match = rb_intern ("match" );
1480
1482
i_keys = rb_intern ("keys" );
1481
1483
i_dup = rb_intern ("dup" );
1484
+
1485
+ usascii_encindex = rb_usascii_encindex ();
1486
+ utf8_encindex = rb_utf8_encindex ();
1482
1487
}
0 commit comments