| Index: src/objects-inl.h
|
| diff --git a/src/objects-inl.h b/src/objects-inl.h
|
| index 4cc9b9f8340238549a12136218672eb205771007..33f89439e64aeb40d768df69a97393512cfa9cbe 100644
|
| --- a/src/objects-inl.h
|
| +++ b/src/objects-inl.h
|
| @@ -3025,6 +3025,38 @@ void Map::ClearCodeCache() {
|
| }
|
|
|
|
|
| +void JSArray::Resize(int required_size) {
|
| + ASSERT(HasFastElements());
|
| + int current_length = Smi::cast(this->length())->value();
|
| + Array* elts = elements();
|
| + if (required_size < current_length) {
|
| + // Set length before potentially expanding. If a new backing array is
|
| + // allocated, we will only copy the data below the new length.
|
| + this->set_length(Smi::FromInt(required_size));
|
| + }
|
| + const int kArraySizeThatFitsComfortablyInNewSpace = 128;
|
| + if (elts->length() < required_size) {
|
| + // Doubling in size would be overkill, but leave some slack to avoid
|
| + // constantly growing.
|
| + Expand(required_size + (required_size >> 3));
|
| + // It's a performance benefit to keep a frequently used array in new-space.
|
| + } else if (!Heap::InNewSpace(elts) &&
|
| + required_size < kArraySizeThatFitsComfortablyInNewSpace) {
|
| + // Expand will allocate a new backing store in new space even if the size
|
| + // we asked for isn't larger than what we had before.
|
| + Expand(required_size);
|
| + } else {
|
| + // Using same backing store.
|
| + if (current_length > required_size) {
|
| + for (int i = required_size; i < current_length; i++) {
|
| + FixedArray::cast(elts)->set_the_hole(i);
|
| + }
|
| + return;
|
| + }
|
| + }
|
| +}
|
| +
|
| +
|
| void JSArray::EnsureSize(int required_size) {
|
| ASSERT(HasFastElements());
|
| Array* elts = elements();
|
|
|