@@ -6133,18 +6133,59 @@ vm_opt_ary_freeze(VALUE ary, int bop, ID id)
61336133 }
61346134}
61356135
6136+ static struct rb_id_table * method_id_table = NULL ;
6137+
61366138static VALUE
61376139vm_opt_respond_to (VALUE recv , VALUE mid )
61386140{
6139- if (SYMBOL_P (mid )) {
6140- printf ("symbol:" );
6141- } else if (STRING_P (mid )) {
6142- printf ("string:" );
6141+ if (method_id_table == NULL ) {
6142+ const char * method_names [] = {
6143+ "rationalize" , "&" , "===" , "inspect" , "=~" , "to_a" , "to_s" , "to_i" , "to_f" , "to_r" ,
6144+ "to_c" , "nil?" , "pretty_print_cycle" , "|" , "to_h" , "^" , "to_json" , "to_yaml" ,
6145+ "pretty_print" , "pretty_print_instance_variables" , "pretty_print_inspect" , "singleton_class" ,
6146+ "dup" , "itself" , "methods" , "singleton_methods" , "protected_methods" , "private_methods" ,
6147+ "public_methods" , "instance_variables" , "instance_variable_get" , "instance_variable_set" ,
6148+ "instance_variable_defined?" , "remove_instance_variable" , "instance_of?" , "kind_of?" ,
6149+ "is_a?" , "display" , "frozen?" , "class" , "then" , "yield_self" , "tap" , "TypeName" ,
6150+ "public_send" , "extend" , "clone" , "<=>" , "pretty_inspect" , "!~" , "method" , "eql?" ,
6151+ "respond_to?" , "public_method" , "singleton_method" , "define_singleton_method" , "hash" ,
6152+ "freeze" , "object_id" , "Namespace" , "send" , "to_enum" , "enum_for" , "equal?" , "!" ,
6153+ "__send__" , "==" , "!=" , "__id__" , "instance_eval" , "instance_exec"
6154+ };
6155+
6156+ size_t method_names_size = sizeof (method_names ) / sizeof (method_names [0 ]);
6157+ method_id_table = rb_id_table_create (method_names_size );
6158+
6159+ for (size_t i = 0 ; i < method_names_size ; i ++ ) {
6160+ ID id = rb_intern (method_names [i ]);
6161+ rb_id_table_insert (method_id_table , id , Qtrue );
6162+ }
6163+ }
6164+ if (NIL_P (recv )) {
6165+ ID id = rb_check_id (& mid );
6166+ if (!id ) return Qfalse ;
6167+
6168+ VALUE val ;
6169+ if (rb_id_table_lookup (method_id_table , id , & val )) {
6170+ return Qtrue ;
6171+ } else {
6172+ return Qfalse ;
6173+ }
61436174 }
6144- printf ( "%s\n" , rb_builtin_type_name ( TYPE ( recv )));
6175+
61456176 return Qundef ;
61466177}
61476178
6179+ // static VALUE
6180+ // vm_opt_respond_to(VALUE recv, VALUE mid)
6181+ // {
6182+ // if (NIL_P(recv)) {
6183+ // return Qfalse;
6184+ // }
6185+
6186+ // return Qundef;
6187+ // }
6188+
61486189static VALUE
61496190vm_opt_hash_freeze (VALUE hash , int bop , ID id )
61506191{
0 commit comments