OLD | NEW |
1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2012 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 "src/elements.h" | 5 #include "src/elements.h" |
6 | 6 |
7 #include "src/arguments.h" | 7 #include "src/arguments.h" |
8 #include "src/conversions.h" | 8 #include "src/conversions.h" |
9 #include "src/factory.h" | 9 #include "src/factory.h" |
10 #include "src/messages.h" | 10 #include "src/messages.h" |
(...skipping 516 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
527 uint32_t end) { | 527 uint32_t end) { |
528 if (IsFastPackedElementsKind(kind())) return true; | 528 if (IsFastPackedElementsKind(kind())) return true; |
529 for (uint32_t i = start; i < end; i++) { | 529 for (uint32_t i = start; i < end; i++) { |
530 if (!ElementsAccessorSubclass::HasElementImpl(holder, i, backing_store)) { | 530 if (!ElementsAccessorSubclass::HasElementImpl(holder, i, backing_store)) { |
531 return false; | 531 return false; |
532 } | 532 } |
533 } | 533 } |
534 return true; | 534 return true; |
535 } | 535 } |
536 | 536 |
| 537 static void TryTransitionResultArrayToPacked(Handle<JSArray> array) { |
| 538 if (!IsHoleyElementsKind(kind())) return; |
| 539 int length = Smi::cast(array->length())->value(); |
| 540 Handle<FixedArrayBase> backing_store(array->elements()); |
| 541 if (!ElementsAccessorSubclass::IsPackedImpl(array, backing_store, 0, |
| 542 length)) { |
| 543 return; |
| 544 } |
| 545 ElementsKind packed_kind = GetPackedElementsKind(kind()); |
| 546 Handle<Map> new_map = |
| 547 JSObject::GetElementsTransitionMap(array, packed_kind); |
| 548 JSObject::MigrateToMap(array, new_map); |
| 549 if (FLAG_trace_elements_transitions) { |
| 550 JSObject::PrintElementsTransition(stdout, array, kind(), backing_store, |
| 551 packed_kind, backing_store); |
| 552 } |
| 553 } |
| 554 |
537 virtual bool HasElement(Handle<JSObject> holder, uint32_t index, | 555 virtual bool HasElement(Handle<JSObject> holder, uint32_t index, |
538 Handle<FixedArrayBase> backing_store) final { | 556 Handle<FixedArrayBase> backing_store) final { |
539 return ElementsAccessorSubclass::HasElementImpl(holder, index, | 557 return ElementsAccessorSubclass::HasElementImpl(holder, index, |
540 backing_store); | 558 backing_store); |
541 } | 559 } |
542 | 560 |
543 static bool HasElementImpl(Handle<JSObject> holder, uint32_t index, | 561 static bool HasElementImpl(Handle<JSObject> holder, uint32_t index, |
544 Handle<FixedArrayBase> backing_store) { | 562 Handle<FixedArrayBase> backing_store) { |
545 return ElementsAccessorSubclass::GetEntryForIndexImpl( | 563 return ElementsAccessorSubclass::GetEntryForIndexImpl( |
546 *holder, *backing_store, index) != kMaxUInt32; | 564 *holder, *backing_store, index) != kMaxUInt32; |
(...skipping 891 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1438 uint32_t start, uint32_t end) { | 1456 uint32_t start, uint32_t end) { |
1439 DCHECK(start < end); | 1457 DCHECK(start < end); |
1440 Isolate* isolate = receiver->GetIsolate(); | 1458 Isolate* isolate = receiver->GetIsolate(); |
1441 int result_len = end - start; | 1459 int result_len = end - start; |
1442 Handle<JSArray> result_array = isolate->factory()->NewJSArray( | 1460 Handle<JSArray> result_array = isolate->factory()->NewJSArray( |
1443 KindTraits::Kind, result_len, result_len); | 1461 KindTraits::Kind, result_len, result_len); |
1444 DisallowHeapAllocation no_gc; | 1462 DisallowHeapAllocation no_gc; |
1445 FastElementsAccessorSubclass::CopyElementsImpl( | 1463 FastElementsAccessorSubclass::CopyElementsImpl( |
1446 *backing_store, start, result_array->elements(), KindTraits::Kind, 0, | 1464 *backing_store, start, result_array->elements(), KindTraits::Kind, 0, |
1447 kPackedSizeNotKnown, result_len); | 1465 kPackedSizeNotKnown, result_len); |
| 1466 FastElementsAccessorSubclass::TryTransitionResultArrayToPacked( |
| 1467 result_array); |
1448 return result_array; | 1468 return result_array; |
1449 } | 1469 } |
1450 | 1470 |
1451 static Handle<JSArray> SpliceImpl(Handle<JSArray> receiver, | 1471 static Handle<JSArray> SpliceImpl(Handle<JSArray> receiver, |
1452 Handle<FixedArrayBase> backing_store, | 1472 Handle<FixedArrayBase> backing_store, |
1453 uint32_t start, uint32_t delete_count, | 1473 uint32_t start, uint32_t delete_count, |
1454 Arguments* args, uint32_t add_count) { | 1474 Arguments* args, uint32_t add_count) { |
1455 Isolate* isolate = receiver->GetIsolate(); | 1475 Isolate* isolate = receiver->GetIsolate(); |
1456 Heap* heap = isolate->heap(); | 1476 Heap* heap = isolate->heap(); |
1457 uint32_t len = Smi::cast(receiver->length())->value(); | 1477 uint32_t len = Smi::cast(receiver->length())->value(); |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1492 for (uint32_t index = 0; index < add_count; index++) { | 1512 for (uint32_t index = 0; index < add_count; index++) { |
1493 Object* object = (*args)[3 + index]; | 1513 Object* object = (*args)[3 + index]; |
1494 FastElementsAccessorSubclass::SetImpl(raw_backing_store, index + start, | 1514 FastElementsAccessorSubclass::SetImpl(raw_backing_store, index + start, |
1495 object, mode); | 1515 object, mode); |
1496 } | 1516 } |
1497 | 1517 |
1498 if (elms_changed) { | 1518 if (elms_changed) { |
1499 receiver->set_elements(*backing_store); | 1519 receiver->set_elements(*backing_store); |
1500 } | 1520 } |
1501 receiver->set_length(Smi::FromInt(new_length)); | 1521 receiver->set_length(Smi::FromInt(new_length)); |
| 1522 FastElementsAccessorSubclass::TryTransitionResultArrayToPacked( |
| 1523 deleted_elements); |
1502 return deleted_elements; | 1524 return deleted_elements; |
1503 } | 1525 } |
1504 | 1526 |
1505 private: | 1527 private: |
1506 static bool SpliceShrinkStep(Handle<FixedArrayBase>& backing_store, | 1528 static bool SpliceShrinkStep(Handle<FixedArrayBase>& backing_store, |
1507 Heap* heap, uint32_t start, | 1529 Heap* heap, uint32_t start, |
1508 uint32_t delete_count, uint32_t add_count, | 1530 uint32_t delete_count, uint32_t add_count, |
1509 uint32_t len, uint32_t new_length) { | 1531 uint32_t len, uint32_t new_length) { |
1510 const int move_left_count = len - delete_count - start; | 1532 const int move_left_count = len - delete_count - start; |
1511 const int move_left_dst_index = start + add_count; | 1533 const int move_left_dst_index = start + add_count; |
(...skipping 897 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2409 } | 2431 } |
2410 } | 2432 } |
2411 | 2433 |
2412 DCHECK(j == result_len); | 2434 DCHECK(j == result_len); |
2413 return result_array; | 2435 return result_array; |
2414 } | 2436 } |
2415 | 2437 |
2416 ElementsAccessor** ElementsAccessor::elements_accessors_ = NULL; | 2438 ElementsAccessor** ElementsAccessor::elements_accessors_ = NULL; |
2417 } // namespace internal | 2439 } // namespace internal |
2418 } // namespace v8 | 2440 } // namespace v8 |
OLD | NEW |