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

Side by Side Diff: src/objects.cc

Issue 1190143002: Minor cleanup in element handling (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Created 5 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
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2013 the V8 project authors. All rights reserved. 1 // Copyright 2013 the V8 project authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include <iomanip> 5 #include <iomanip>
6 #include <sstream> 6 #include <sstream>
7 7
8 #include "src/v8.h" 8 #include "src/v8.h"
9 9
10 #include "src/accessors.h" 10 #include "src/accessors.h"
(...skipping 12471 matching lines...) Expand 10 before | Expand all | Expand 10 after
12482 convert_to_slow = false; 12482 convert_to_slow = false;
12483 } 12483 }
12484 } 12484 }
12485 if (convert_to_slow) { 12485 if (convert_to_slow) {
12486 NormalizeElements(object); 12486 NormalizeElements(object);
12487 AddDictionaryElement(object, index, value, NONE); 12487 AddDictionaryElement(object, index, value, NONE);
12488 return; 12488 return;
12489 } 12489 }
12490 } 12490 }
12491 12491
12492 // Convert to fast double elements if appropriate. 12492 if (object->HasFastSmiElements() && !value->IsSmi()) {
12493 if (object->HasFastSmiElements() && !value->IsSmi() && value->IsNumber()) { 12493 // Convert to fast double elements if appropriate.
12494 // Consider fixing the boilerplate as well if we have one. 12494 if (value->IsNumber()) {
12495 ElementsKind to_kind = IsHoleyElementsKind(object->GetElementsKind()) 12495 // Consider fixing the boilerplate as well if we have one.
12496 ? FAST_HOLEY_DOUBLE_ELEMENTS 12496 ElementsKind to_kind = IsHoleyElementsKind(object->GetElementsKind())
12497 : FAST_DOUBLE_ELEMENTS; 12497 ? FAST_HOLEY_DOUBLE_ELEMENTS
12498 : FAST_DOUBLE_ELEMENTS;
12498 12499
12499 UpdateAllocationSite(object, to_kind); 12500 UpdateAllocationSite(object, to_kind);
12500 12501
12501 SetFastDoubleElementsCapacityAndLength(object, new_capacity, array_length); 12502 SetFastDoubleElementsCapacityAndLength(object, new_capacity,
12502 FixedDoubleArray::cast(object->elements())->set(index, value->Number()); 12503 array_length);
12503 JSObject::ValidateElements(object); 12504 FixedDoubleArray::cast(object->elements())->set(index, value->Number());
12504 return; 12505 JSObject::ValidateElements(object);
12505 } 12506 return;
12507 }
12506 12508
12507 // Change elements kind from Smi-only to generic FAST if necessary. 12509 // Change elements kind from Smi-only to generic FAST if necessary.
12508 if (object->HasFastSmiElements() && !value->IsSmi()) {
12509 ElementsKind kind = object->HasFastHoleyElements() 12510 ElementsKind kind = object->HasFastHoleyElements()
12510 ? FAST_HOLEY_ELEMENTS 12511 ? FAST_HOLEY_ELEMENTS
12511 : FAST_ELEMENTS; 12512 : FAST_ELEMENTS;
12512 12513
12513 UpdateAllocationSite(object, kind); 12514 UpdateAllocationSite(object, kind);
12514 Handle<Map> new_map = GetElementsTransitionMap(object, kind); 12515 Handle<Map> new_map = GetElementsTransitionMap(object, kind);
12515 JSObject::MigrateToMap(object, new_map); 12516 JSObject::MigrateToMap(object, new_map);
12516 DCHECK(IsFastObjectElementsKind(object->GetElementsKind())); 12517 DCHECK(IsFastObjectElementsKind(object->GetElementsKind()));
12517 } 12518 }
12518 12519
12519 // Increase backing store capacity if that's been decided previously. 12520 // Increase backing store capacity if that's been decided previously.
12520 if (new_capacity != capacity) { 12521 // Otherwise, set the new element and length.
12522 if (new_capacity == capacity) {
12523 DCHECK(object->elements()->IsFixedArray());
12524 backing_store->set(index, *value);
12525 if (must_update_array_length) {
12526 Handle<JSArray>::cast(object)->set_length(Smi::FromInt(array_length));
12527 }
12528 } else {
12521 SetFastElementsCapacitySmiMode smi_mode = 12529 SetFastElementsCapacitySmiMode smi_mode =
12522 value->IsSmi() && object->HasFastSmiElements() 12530 value->IsSmi() && object->HasFastSmiElements()
12523 ? kAllowSmiElements 12531 ? kAllowSmiElements
12524 : kDontAllowSmiElements; 12532 : kDontAllowSmiElements;
12525 Handle<FixedArray> new_elements = 12533 Handle<FixedArray> new_elements =
12526 SetFastElementsCapacityAndLength(object, new_capacity, array_length, 12534 SetFastElementsCapacityAndLength(object, new_capacity, array_length,
12527 smi_mode); 12535 smi_mode);
12528 new_elements->set(index, *value); 12536 new_elements->set(index, *value);
12529 JSObject::ValidateElements(object); 12537 JSObject::ValidateElements(object);
12530 return;
12531 }
12532
12533 // Finally, set the new element and length.
12534 DCHECK(object->elements()->IsFixedArray());
12535 backing_store->set(index, *value);
12536 if (must_update_array_length) {
12537 Handle<JSArray>::cast(object)->set_length(Smi::FromInt(array_length));
12538 } 12538 }
12539 } 12539 }
12540 12540
12541 12541
12542 void JSObject::SetSloppyArgumentsElement(Handle<JSObject> object, 12542 void JSObject::SetSloppyArgumentsElement(Handle<JSObject> object,
12543 uint32_t index, Handle<Object> value, 12543 uint32_t index, Handle<Object> value,
12544 PropertyAttributes attributes) { 12544 PropertyAttributes attributes) {
12545 // TODO(verwaest): Handle with the elements accessor. 12545 // TODO(verwaest): Handle with the elements accessor.
12546 Isolate* isolate = object->GetIsolate(); 12546 Isolate* isolate = object->GetIsolate();
12547 12547
(...skipping 4103 matching lines...) Expand 10 before | Expand all | Expand 10 after
16651 Handle<Object> new_value) { 16651 Handle<Object> new_value) {
16652 if (cell->value() != *new_value) { 16652 if (cell->value() != *new_value) {
16653 cell->set_value(*new_value); 16653 cell->set_value(*new_value);
16654 Isolate* isolate = cell->GetIsolate(); 16654 Isolate* isolate = cell->GetIsolate();
16655 cell->dependent_code()->DeoptimizeDependentCodeGroup( 16655 cell->dependent_code()->DeoptimizeDependentCodeGroup(
16656 isolate, DependentCode::kPropertyCellChangedGroup); 16656 isolate, DependentCode::kPropertyCellChangedGroup);
16657 } 16657 }
16658 } 16658 }
16659 } // namespace internal 16659 } // namespace internal
16660 } // namespace v8 16660 } // namespace v8
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698