зеркало из https://github.com/github/ruby.git
* array.c (rb_ary_sample): use frozen shared array to get rid of
reallocation. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@29092 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
Родитель
c6465aeeb1
Коммит
569d821929
|
@ -1,3 +1,8 @@
|
|||
Wed Aug 25 17:56:40 2010 Nobuyoshi Nakada <nobu@ruby-lang.org>
|
||||
|
||||
* array.c (rb_ary_sample): use frozen shared array to get rid of
|
||||
reallocation.
|
||||
|
||||
Wed Aug 25 03:42:43 2010 NAKAMURA Usaku <usa@ruby-lang.org>
|
||||
|
||||
* ext/dl/cfunc.c (rb_dlcfunc_call): workaround for VC9 for x64.
|
||||
|
|
2
array.c
2
array.c
|
@ -3826,6 +3826,7 @@ rb_ary_sample(int argc, VALUE *argv, VALUE ary)
|
|||
rb_scan_args(argc, argv, "1", &nv);
|
||||
n = NUM2LONG(nv);
|
||||
if (n < 0) rb_raise(rb_eArgError, "negative sample number");
|
||||
RB_GC_GUARD(ary) = ary_make_shared(ary);
|
||||
ptr = RARRAY_PTR(ary);
|
||||
len = RARRAY_LEN(ary);
|
||||
if (n > len) n = len;
|
||||
|
@ -3872,7 +3873,6 @@ rb_ary_sample(int argc, VALUE *argv, VALUE ary)
|
|||
VALUE *ptr_result;
|
||||
result = rb_ary_new4(len, ptr);
|
||||
ptr_result = RARRAY_PTR(result);
|
||||
RB_GC_GUARD(ary);
|
||||
for (i=0; i<n; i++) {
|
||||
j = RAND_UPTO(len-i) + i;
|
||||
nv = ptr_result[j];
|
||||
|
|
Загрузка…
Ссылка в новой задаче