Feature #4893 » String_call_initialize_v5.diff
string.c | ||
---|---|---|
return str;
|
||
}
|
||
extern void rb_obj_call_init_fast(VALUE obj, int argc, VALUE *argv);
|
||
VALUE
|
||
rb_str_new(const char *ptr, long len)
|
||
{
|
||
/* str is already initialized by original initialize within str_new() */
|
||
VALUE str = str_new(rb_cString, ptr, len);
|
||
/* speed: call initialize only if it was redefined. See #4893 */
|
||
/* passing str itself as parameter, avoiding need for a temp str */
|
||
rb_obj_call_init_fast((VALUE)str, 1, &str);
|
||
return str;
|
||
return str_new(rb_cString, ptr, len);
|
||
}
|
||
VALUE
|
vm_method.c | ||
---|---|---|
}
|
||
}
|
||
/* use class-variable (bit-flag). TODO: move to header file */
|
||
#define FL_CALL_INIT FL_USER18
|
||
void
|
||
rb_set_call_flags(VALUE klass, ID mid, int set)
|
||
{
|
||
/* if used for more classes, introduce FL_FAST_CLASS to mark*/
|
||
if (ruby_running && mid == idInitialize && klass == rb_cString) {
|
||
if (set) {
|
||
FL_SET(klass, FL_CALL_INIT);
|
||
} else {
|
||
FL_UNSET(klass, FL_CALL_INIT);
|
||
}
|
||
}
|
||
}
|
||
void
|
||
rb_obj_call_init_fast(VALUE obj, int argc, VALUE *argv)
|
||
{
|
||
/* use only in fast_classes like String. Method lookup and call of initialize
|
||
will be done only, if initialize was redefined. */
|
||
if (FL_TEST(CLASS_OF(obj), FL_CALL_INIT)) {
|
||
rb_obj_call_init(obj, argc, argv);
|
||
}
|
||
}
|
||
rb_method_entry_t *
|
||
rb_add_method(VALUE klass, ID mid, rb_method_type_t type, void *opts, rb_method_flag_t noex)
|
||
{
|
||
... | ... | |
default:
|
||
rb_bug("rb_add_method: unsupported method type (%d)\n", type);
|
||
}
|
||
rb_set_call_flags(klass, mid, TRUE);
|
||
if (type != VM_METHOD_TYPE_UNDEF) {
|
||
method_added(klass, mid);
|
||
}
|
||
... | ... | |
rb_vm_check_redefinition_opt_method(me);
|
||
rb_clear_cache_for_undef(klass, mid);
|
||
rb_unlink_method_entry(me);
|
||
rb_set_call_flags(klass, mid, FALSE);
|
||
CALL_METHOD_HOOK(klass, removed, mid);
|
||
}
|
||
... | ... | |
rb_add_method(klass, id, VM_METHOD_TYPE_UNDEF, 0, NOEX_PUBLIC);
|
||
rb_set_call_flags(klass, id, FALSE);
|
||
CALL_METHOD_HOOK(klass, undefined, id);
|
||
}
|
||