r37410-adapted37582-partially.patch

_ wanabe, 11/29/2012 12:33 AM

Download (1.38 KB)

View differences:

array.c
274 274
    }
275 275
}
276 276

  
277
static void
278
ary_ensure_room_for_push(VALUE ary, long add_len)
279
{
280
    long new_len = RARRAY_LEN(ary) + add_len;
281
    long capa;
282

  
283
    if (ARY_SHARED_P(ary)) {
284
	if (new_len > RARRAY_EMBED_LEN_MAX) {
285
	    VALUE shared = ARY_SHARED(ary);
286
	    if (ARY_SHARED_NUM(shared) == 1) {
287
		if (RARRAY_PTR(ary) - RARRAY_PTR(shared) + new_len <= RARRAY_LEN(shared)) {
288
		    rb_ary_modify_check(ary);
289
		}
290
		else {
291
		    /* if array is shared, than it is likely it participate in push/shift pattern */
292
		    rb_ary_modify(ary);
293
		    capa = ARY_CAPA(ary);
294
		    if (new_len > capa - (capa >> 6)) {
295
			ary_double_capa(ary, new_len);
296
		    }
297
		}
298
		return;
299
	    }
300
	}
301
    }
302
    rb_ary_modify(ary);
303
    capa = ARY_CAPA(ary);
304
    if (new_len > capa) {
305
	ary_double_capa(ary, new_len);
306
    }
307
}
308

  
277 309
/*
278 310
 *  call-seq:
279 311
 *      ary.freeze -> ary
......
766 798
VALUE
767 799
rb_ary_cat(VALUE ary, const VALUE *ptr, long len)
768 800
{
769
    long oldlen;
801
    long oldlen = RARRAY_LEN(ary);
770 802

  
771
    rb_ary_modify(ary);
772
    oldlen = RARRAY_LEN(ary);
773
    ary_resize_capa(ary, oldlen + len);
803
    ary_ensure_room_for_push(ary, len);
774 804
    MEMCPY(RARRAY_PTR(ary) + oldlen, ptr, VALUE, len);
775 805
    ARY_SET_LEN(ary, oldlen + len);
776 806
    return ary;