Project

General

Profile

Feature #4893 ยป String_call_initialize_v5b.diff

corrected a polarity-error in patch v5 - lazaridis.com (Lazaridis Ilias), 07/17/2011 12:01 PM

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

  
409 411
VALUE
410 412
rb_str_new(const char *ptr, long len)
411 413
{
412
    return str_new(rb_cString, ptr, len);
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;
413 422
}
414 423

  
415 424
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

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

  
336
    rb_set_call_flags(klass, mid, TRUE);
337

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

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

  
......
628 659

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

  
662
    rb_set_call_flags(klass, id, FALSE);
663

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