Revision: 8396
Author: [email protected]
Date: Thu Jun 23 04:22:21 2011
Log: Trim fast elements tail on significant length decreases.
Runtime_RegExpExecMultiple had to be updated because it assumed
setting an array's length to zero still keeps some capacity in the
backing store.
[email protected]
Review URL: http://codereview.chromium.org/7237004
http://code.google.com/p/v8/source/detail?r=8396
Modified:
/branches/bleeding_edge/src/objects.cc
/branches/bleeding_edge/src/runtime.cc
=======================================
--- /branches/bleeding_edge/src/objects.cc Thu Jun 23 02:30:39 2011
+++ /branches/bleeding_edge/src/objects.cc Thu Jun 23 04:22:21 2011
@@ -7533,12 +7533,24 @@
{ MaybeObject* maybe_obj = EnsureWritableFastElements();
if (!maybe_obj->ToObject(&obj)) return maybe_obj;
}
- int old_length =
FastD2I(JSArray::cast(this)->length()->Number());
- // NOTE: We may be able to optimize this by removing the
- // last part of the elements backing storage array and
- // setting the capacity to the new size.
- for (int i = value; i < old_length; i++) {
- FixedArray::cast(elements())->set_the_hole(i);
+ FixedArray* fast_elements = FixedArray::cast(elements());
+ if (2 * value <= old_capacity) {
+ // If more than half the elements won't be used, trim the
array.
+ if (value == 0) {
+ initialize_elements();
+ } else {
+ fast_elements->set_length(value);
+ Address filler_start = fast_elements->address() +
+
FixedArray::OffsetOfElementAt(value);
+ int filler_size = (old_capacity - value) * kPointerSize;
+ GetHeap()->CreateFillerObjectAt(filler_start, filler_size);
+ }
+ } else {
+ // Otherwise, fill the unused tail with holes.
+ int old_length =
FastD2I(JSArray::cast(this)->length()->Number());
+ for (int i = value; i < old_length; i++) {
+ fast_elements->set_the_hole(i);
+ }
}
JSArray::cast(this)->set_length(Smi::cast(smi_length));
}
=======================================
--- /branches/bleeding_edge/src/runtime.cc Wed Jun 22 07:20:23 2011
+++ /branches/bleeding_edge/src/runtime.cc Thu Jun 23 04:22:21 2011
@@ -3532,7 +3532,8 @@
if (result_array->HasFastElements()) {
result_elements =
Handle<FixedArray>(FixedArray::cast(result_array->elements()));
- } else {
+ }
+ if (result_elements.is_null() || result_elements->length() < 16) {
result_elements = isolate->factory()->NewFixedArrayWithHoles(16);
}
FixedArrayBuilder builder(result_elements);
--
v8-dev mailing list
[email protected]
http://groups.google.com/group/v8-dev