Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(7)

Side by Side Diff: src/objects.cc

Issue 7237004: Trim fast elements tail on significant length decreases. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Created 9 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | src/runtime.cc » ('j') | src/runtime.cc » ('J')
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2011 the V8 project authors. All rights reserved. 1 // Copyright 2011 the V8 project authors. All rights reserved.
2 // Redistribution and use in source and binary forms, with or without 2 // Redistribution and use in source and binary forms, with or without
3 // modification, are permitted provided that the following conditions are 3 // modification, are permitted provided that the following conditions are
4 // met: 4 // met:
5 // 5 //
6 // * Redistributions of source code must retain the above copyright 6 // * Redistributions of source code must retain the above copyright
7 // notice, this list of conditions and the following disclaimer. 7 // notice, this list of conditions and the following disclaimer.
8 // * Redistributions in binary form must reproduce the above 8 // * Redistributions in binary form must reproduce the above
9 // copyright notice, this list of conditions and the following 9 // copyright notice, this list of conditions and the following
10 // disclaimer in the documentation and/or other materials provided 10 // disclaimer in the documentation and/or other materials provided
(...skipping 7489 matching lines...) Expand 10 before | Expand all | Expand 10 after
7500 if (value < 0) return ArrayLengthRangeError(GetHeap()); 7500 if (value < 0) return ArrayLengthRangeError(GetHeap());
7501 switch (GetElementsKind()) { 7501 switch (GetElementsKind()) {
7502 case FAST_ELEMENTS: { 7502 case FAST_ELEMENTS: {
7503 int old_capacity = FixedArray::cast(elements())->length(); 7503 int old_capacity = FixedArray::cast(elements())->length();
7504 if (value <= old_capacity) { 7504 if (value <= old_capacity) {
7505 if (IsJSArray()) { 7505 if (IsJSArray()) {
7506 Object* obj; 7506 Object* obj;
7507 { MaybeObject* maybe_obj = EnsureWritableFastElements(); 7507 { MaybeObject* maybe_obj = EnsureWritableFastElements();
7508 if (!maybe_obj->ToObject(&obj)) return maybe_obj; 7508 if (!maybe_obj->ToObject(&obj)) return maybe_obj;
7509 } 7509 }
7510 int old_length = FastD2I(JSArray::cast(this)->length()->Number()); 7510 FixedArray* fast_elements = FixedArray::cast(elements());
7511 // NOTE: We may be able to optimize this by removing the 7511 if (2 * value <= old_capacity) {
7512 // last part of the elements backing storage array and 7512 // If more than half the elements won't be used, trim the array.
7513 // setting the capacity to the new size. 7513 if (value == 0) {
7514 for (int i = value; i < old_length; i++) { 7514 initialize_elements();
7515 FixedArray::cast(elements())->set_the_hole(i); 7515 } else {
7516 fast_elements->set_length(value);
7517 Address filler_start = fast_elements->address() +
7518 FixedArray::OffsetOfElementAt(value);
7519 int filler_size = (old_capacity - value) * kPointerSize;
7520 GetHeap()->CreateFillerObjectAt(filler_start, filler_size);
7521 }
7522 } else {
7523 // Otherwise, fill the unused tail with holes.
7524 int old_length = FastD2I(JSArray::cast(this)->length()->Number());
7525 for (int i = value; i < old_length; i++) {
7526 fast_elements->set_the_hole(i);
7527 }
7516 } 7528 }
7517 JSArray::cast(this)->set_length(Smi::cast(smi_length)); 7529 JSArray::cast(this)->set_length(Smi::cast(smi_length));
7518 } 7530 }
7519 return this; 7531 return this;
7520 } 7532 }
7521 int min = NewElementsCapacity(old_capacity); 7533 int min = NewElementsCapacity(old_capacity);
7522 int new_capacity = value > min ? value : min; 7534 int new_capacity = value > min ? value : min;
7523 if (new_capacity <= kMaxFastElementsLength || 7535 if (new_capacity <= kMaxFastElementsLength ||
7524 !ShouldConvertToSlowElements(new_capacity)) { 7536 !ShouldConvertToSlowElements(new_capacity)) {
7525 MaybeObject* result = 7537 MaybeObject* result =
(...skipping 4035 matching lines...) Expand 10 before | Expand all | Expand 10 after
11561 if (break_point_objects()->IsUndefined()) return 0; 11573 if (break_point_objects()->IsUndefined()) return 0;
11562 // Single beak point. 11574 // Single beak point.
11563 if (!break_point_objects()->IsFixedArray()) return 1; 11575 if (!break_point_objects()->IsFixedArray()) return 1;
11564 // Multiple break points. 11576 // Multiple break points.
11565 return FixedArray::cast(break_point_objects())->length(); 11577 return FixedArray::cast(break_point_objects())->length();
11566 } 11578 }
11567 #endif 11579 #endif
11568 11580
11569 11581
11570 } } // namespace v8::internal 11582 } } // namespace v8::internal
OLDNEW
« no previous file with comments | « no previous file | src/runtime.cc » ('j') | src/runtime.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698