Index: src/objects-inl.h |
=================================================================== |
--- src/objects-inl.h (revision 3335) |
+++ src/objects-inl.h (working copy) |
@@ -3103,8 +3103,18 @@ |
void JSArray::EnsureSize(int required_size) { |
ASSERT(HasFastElements()); |
- if (elements()->length() >= required_size) return; |
- Expand(required_size); |
+ Array* elts = elements(); |
+ 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)); |
+ } else if (!Heap::new_space()->Contains(elts)) { |
+ // It's a performance benefit to keep a frequently used array in new-space. |
+ const int kArraySizeThatFitsComfortablyInNewSpace = 128; |
Søren Thygesen Gjesse
2009/11/19 21:42:57
This does not take the calculation required_size +
Erik Corry
2009/11/20 10:12:46
Since it's a number I pulled out of my backside I
|
+ if (required_size < kArraySizeThatFitsComfortablyInNewSpace) { |
Søren Thygesen Gjesse
2009/11/19 21:42:57
Maybe combine these two if's into one if condition
Erik Corry
2009/11/20 10:12:46
Done.
|
+ Expand(required_size); |
+ } |
+ } |
} |