| OLD | NEW |
| 1 // Copyright 2015 the V8 project authors. All rights reserved. | 1 // Copyright 2015 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/interpreter/constant-array-builder.h" | 5 #include "src/interpreter/constant-array-builder.h" |
| 6 | 6 |
| 7 #include "src/isolate.h" | 7 #include "src/isolate.h" |
| 8 #include "src/objects-inl.h" | 8 #include "src/objects-inl.h" |
| 9 | 9 |
| 10 namespace v8 { | 10 namespace v8 { |
| (...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 80 } | 80 } |
| 81 UNREACHABLE(); | 81 UNREACHABLE(); |
| 82 return nullptr; | 82 return nullptr; |
| 83 } | 83 } |
| 84 | 84 |
| 85 Handle<Object> ConstantArrayBuilder::At(size_t index) const { | 85 Handle<Object> ConstantArrayBuilder::At(size_t index) const { |
| 86 const ConstantArraySlice* slice = IndexToSlice(index); | 86 const ConstantArraySlice* slice = IndexToSlice(index); |
| 87 if (index < slice->start_index() + slice->size()) { | 87 if (index < slice->start_index() + slice->size()) { |
| 88 return slice->At(index); | 88 return slice->At(index); |
| 89 } else { | 89 } else { |
| 90 DCHECK_LT(index, slice->capacity()); |
| 90 return isolate_->factory()->the_hole_value(); | 91 return isolate_->factory()->the_hole_value(); |
| 91 } | 92 } |
| 92 } | 93 } |
| 93 | 94 |
| 94 Handle<FixedArray> ConstantArrayBuilder::ToFixedArray() { | 95 Handle<FixedArray> ConstantArrayBuilder::ToFixedArray() { |
| 95 Handle<FixedArray> fixed_array = isolate_->factory()->NewFixedArray( | 96 Handle<FixedArray> fixed_array = isolate_->factory()->NewFixedArray( |
| 96 static_cast<int>(size()), PretenureFlag::TENURED); | 97 static_cast<int>(size()), PretenureFlag::TENURED); |
| 97 int array_index = 0; | 98 int array_index = 0; |
| 98 for (const ConstantArraySlice* slice : idx_slice_) { | 99 for (const ConstantArraySlice* slice : idx_slice_) { |
| 99 if (array_index == fixed_array->length()) { | 100 if (array_index == fixed_array->length()) { |
| 100 break; | 101 break; |
| 101 } | 102 } |
| 103 DCHECK(array_index == 0 || |
| 104 base::bits::IsPowerOfTwo32(static_cast<uint32_t>(array_index))); |
| 102 // Copy objects from slice into array. | 105 // Copy objects from slice into array. |
| 103 for (size_t i = 0; i < slice->size(); ++i) { | 106 for (size_t i = 0; i < slice->size(); ++i) { |
| 104 fixed_array->set(array_index++, *slice->At(slice->start_index() + i)); | 107 fixed_array->set(array_index++, *slice->At(slice->start_index() + i)); |
| 105 } | 108 } |
| 106 // Insert holes where reservations led to unused slots. | 109 // Insert holes where reservations led to unused slots. |
| 107 size_t padding = | 110 size_t padding = |
| 108 std::min(static_cast<size_t>(fixed_array->length() - array_index), | 111 std::min(static_cast<size_t>(fixed_array->length() - array_index), |
| 109 slice->capacity() - slice->size()); | 112 slice->capacity() - slice->size()); |
| 110 for (size_t i = slice->start_index() + slice->size(); | 113 for (size_t i = 0; i < padding; i++) { |
| 111 i < slice->start_index() + padding; ++i) { | |
| 112 fixed_array->set(array_index++, *isolate_->factory()->the_hole_value()); | 114 fixed_array->set(array_index++, *isolate_->factory()->the_hole_value()); |
| 113 } | 115 } |
| 114 } | 116 } |
| 115 DCHECK_EQ(array_index, fixed_array->length()); | 117 DCHECK_EQ(array_index, fixed_array->length()); |
| 116 constants_map()->Clear(); | 118 constants_map()->Clear(); |
| 117 return fixed_array; | 119 return fixed_array; |
| 118 } | 120 } |
| 119 | 121 |
| 120 size_t ConstantArrayBuilder::Insert(Handle<Object> object) { | 122 size_t ConstantArrayBuilder::Insert(Handle<Object> object) { |
| 121 index_t* entry = constants_map()->Find(object); | 123 index_t* entry = constants_map()->Find(object); |
| (...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 187 return index; | 189 return index; |
| 188 } | 190 } |
| 189 | 191 |
| 190 void ConstantArrayBuilder::DiscardReservedEntry(OperandSize operand_size) { | 192 void ConstantArrayBuilder::DiscardReservedEntry(OperandSize operand_size) { |
| 191 OperandSizeToSlice(operand_size)->Unreserve(); | 193 OperandSizeToSlice(operand_size)->Unreserve(); |
| 192 } | 194 } |
| 193 | 195 |
| 194 } // namespace interpreter | 196 } // namespace interpreter |
| 195 } // namespace internal | 197 } // namespace internal |
| 196 } // namespace v8 | 198 } // namespace v8 |
| OLD | NEW |