Skip to content

Commit

Permalink
Actually commit fixes for #3634.
Browse files Browse the repository at this point in the history
  • Loading branch information
brixen committed Apr 5, 2016
1 parent 40b599c commit 62e647d
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 6 deletions.
19 changes: 14 additions & 5 deletions machine/builtin/array.cpp
Expand Up @@ -63,13 +63,14 @@ namespace rubinius {
return ary;
}

Array* Array::new_range(STATE, Fixnum* start, Fixnum* count) {
Array* Array::new_range(STATE, Fixnum* index, Fixnum* count) {
Array* ary = state->memory()->new_object<Array>(state, class_object(state));

native_int total = count->to_native();
if(total <= 0) {
native_int new_size = count->to_native();
if(new_size <= 0) {
ary->tuple(state, Tuple::create(state, 0));
} else {
ary->start(state, Fixnum::from(0));
ary->total(state, count);

/* We must use Tuple::create here and not new_fields<Tuple>, or we must
Expand All @@ -82,12 +83,20 @@ namespace rubinius {
* happen infrequently depending on the concurrent marker racing the
* mutator.
*/
Tuple* tup = Tuple::create(state, total);
Tuple* tup = Tuple::create(state, new_size);
ary->tuple(state, tup);

for(native_int i = 0, j = start->to_native(); i < total; i++, j++) {
native_int i = 0;
native_int j = index->to_native();
native_int limit = start()->to_native() + total()->to_native();

for(; i < new_size && j < limit; i++, j++) {
tup->put(state, i, tuple()->field[j]);
}

for(; i < new_size; i++) {
tup->put_nil(i);
}
}

return ary;
Expand Down
2 changes: 1 addition & 1 deletion machine/builtin/array.hpp
Expand Up @@ -41,7 +41,7 @@ namespace rubinius {
static Array* dup_as_array(STATE, Object* obj);

// Rubinius.primitive :array_new_range
Array* new_range(STATE, Fixnum* start, Fixnum* count);
Array* new_range(STATE, Fixnum* index, Fixnum* count);

// Rubinius.primitive :array_new_reserved
Array* new_reserved(STATE, Fixnum* count);
Expand Down

0 comments on commit 62e647d

Please sign in to comment.