Project

General

Profile

Feature #4893 ยป String_call_initialize_v5.diff

no use of callbacks, moved most code to vm_method.c - lazaridis.com (Lazaridis Ilias), 07/17/2011 11:56 AM

View differences:

string.c
406 406
    return str;
407 407
}
408 408

  
409
extern void rb_obj_call_init_fast(VALUE obj, int argc, VALUE *argv);
410

  
411 409
VALUE
412 410
rb_str_new(const char *ptr, long len)
413 411
{
414
    /* str is already initialized by original initialize within str_new() */
415
    VALUE str = str_new(rb_cString, ptr, len);
416

  
417
    /* speed: call initialize only if it was redefined. See #4893 */
418
    /* passing str itself as parameter, avoiding need for a temp str */
419
    rb_obj_call_init_fast((VALUE)str, 1, &str);
420

  
421
    return str;
412
    return str_new(rb_cString, ptr, len);
422 413
}
423 414

  
424 415
VALUE
vm_method.c
258 258
    }
259 259
}
260 260

  
261
/* use class-variable (bit-flag). TODO: move to header file */
262
#define FL_CALL_INIT FL_USER18
263

  
264
void
265
rb_set_call_flags(VALUE klass, ID mid, int set)
266
{
267
/*  if used for more classes, introduce FL_FAST_CLASS to mark*/
268

  
269
	if (ruby_running && mid == idInitialize && klass == rb_cString) {
270
		if (set) {
271
			FL_SET(klass, FL_CALL_INIT);	    
272
		} else {
273
			FL_UNSET(klass, FL_CALL_INIT);	    
274
		}
275
	}
276
}
277

  
278
void
279
rb_obj_call_init_fast(VALUE obj, int argc, VALUE *argv)
280
{
281
/*  use only in fast_classes like String. Method lookup and call of initialize
282
    will be done only, if initialize was redefined. */
283

  
284
	if (FL_TEST(CLASS_OF(obj), FL_CALL_INIT)) {
285
		rb_obj_call_init(obj, argc, argv);
286
	}	
287
}
288

  
289 261
rb_method_entry_t *
290 262
rb_add_method(VALUE klass, ID mid, rb_method_type_t type, void *opts, rb_method_flag_t noex)
291 263
{
......
332 304
      default:
333 305
	rb_bug("rb_add_method: unsupported method type (%d)\n", type);
334 306
    }
335

  
336
    rb_set_call_flags(klass, mid, TRUE);
337

  
338 307
    if (type != VM_METHOD_TYPE_UNDEF) {
339 308
	method_added(klass, mid);
340 309
    }
......
472 441
    rb_vm_check_redefinition_opt_method(me);
473 442
    rb_clear_cache_for_undef(klass, mid);
474 443
    rb_unlink_method_entry(me);
475
    rb_set_call_flags(klass, mid, FALSE);
444

  
476 445
    CALL_METHOD_HOOK(klass, removed, mid);
477 446
}
478 447

  
......
659 628

  
660 629
    rb_add_method(klass, id, VM_METHOD_TYPE_UNDEF, 0, NOEX_PUBLIC);
661 630

  
662
    rb_set_call_flags(klass, id, FALSE);
663

  
664 631
    CALL_METHOD_HOOK(klass, undefined, id);
665 632
}
666 633