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 // Review notes: | 5 // Review notes: |
6 // | 6 // |
7 // - The use of macros in these inline functions may seem superfluous | 7 // - The use of macros in these inline functions may seem superfluous |
8 // but it is absolutely needed to make sure gcc generates optimal | 8 // but it is absolutely needed to make sure gcc generates optimal |
9 // code. gcc is not happy when attempting to inline too deep. | 9 // code. gcc is not happy when attempting to inline too deep. |
10 // | 10 // |
(...skipping 2288 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2299 | 2299 |
2300 Object* FixedArray::get(int index) const { | 2300 Object* FixedArray::get(int index) const { |
2301 SLOW_DCHECK(index >= 0 && index < this->length()); | 2301 SLOW_DCHECK(index >= 0 && index < this->length()); |
2302 return READ_FIELD(this, kHeaderSize + index * kPointerSize); | 2302 return READ_FIELD(this, kHeaderSize + index * kPointerSize); |
2303 } | 2303 } |
2304 | 2304 |
2305 Handle<Object> FixedArray::get(FixedArray* array, int index, Isolate* isolate) { | 2305 Handle<Object> FixedArray::get(FixedArray* array, int index, Isolate* isolate) { |
2306 return handle(array->get(index), isolate); | 2306 return handle(array->get(index), isolate); |
2307 } | 2307 } |
2308 | 2308 |
| 2309 template <class T> |
| 2310 MaybeHandle<T> FixedArray::GetValue(int index) const { |
| 2311 Object* obj = get(index); |
| 2312 if (obj->IsUndefined(GetIsolate())) return MaybeHandle<T>(); |
| 2313 return Handle<T>(T::cast(obj)); |
| 2314 } |
| 2315 |
| 2316 template <class T> |
| 2317 Handle<T> FixedArray::GetValueChecked(int index) const { |
| 2318 Object* obj = get(index); |
| 2319 CHECK(!obj->IsUndefined(GetIsolate())); |
| 2320 return Handle<T>(T::cast(obj)); |
| 2321 } |
2309 | 2322 |
2310 bool FixedArray::is_the_hole(int index) { | 2323 bool FixedArray::is_the_hole(int index) { |
2311 return get(index) == GetHeap()->the_hole_value(); | 2324 return get(index) == GetHeap()->the_hole_value(); |
2312 } | 2325 } |
2313 | 2326 |
2314 | |
2315 void FixedArray::set(int index, Smi* value) { | 2327 void FixedArray::set(int index, Smi* value) { |
2316 DCHECK(map() != GetHeap()->fixed_cow_array_map()); | 2328 DCHECK(map() != GetHeap()->fixed_cow_array_map()); |
2317 DCHECK(index >= 0 && index < this->length()); | 2329 DCHECK(index >= 0 && index < this->length()); |
2318 DCHECK(reinterpret_cast<Object*>(value)->IsSmi()); | 2330 DCHECK(reinterpret_cast<Object*>(value)->IsSmi()); |
2319 int offset = kHeaderSize + index * kPointerSize; | 2331 int offset = kHeaderSize + index * kPointerSize; |
2320 WRITE_FIELD(this, offset, value); | 2332 WRITE_FIELD(this, offset, value); |
2321 } | 2333 } |
2322 | 2334 |
2323 | 2335 |
2324 void FixedArray::set(int index, Object* value) { | 2336 void FixedArray::set(int index, Object* value) { |
(...skipping 1649 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3974 } | 3986 } |
3975 | 3987 |
3976 | 3988 |
3977 int ByteArray::Size() { return RoundUp(length() + kHeaderSize, kPointerSize); } | 3989 int ByteArray::Size() { return RoundUp(length() + kHeaderSize, kPointerSize); } |
3978 | 3990 |
3979 byte ByteArray::get(int index) { | 3991 byte ByteArray::get(int index) { |
3980 DCHECK(index >= 0 && index < this->length()); | 3992 DCHECK(index >= 0 && index < this->length()); |
3981 return READ_BYTE_FIELD(this, kHeaderSize + index * kCharSize); | 3993 return READ_BYTE_FIELD(this, kHeaderSize + index * kCharSize); |
3982 } | 3994 } |
3983 | 3995 |
| 3996 const byte* ByteArray::data() const { |
| 3997 return reinterpret_cast<const byte*>(FIELD_ADDR_CONST(this, kHeaderSize)); |
| 3998 } |
3984 | 3999 |
3985 void ByteArray::set(int index, byte value) { | 4000 void ByteArray::set(int index, byte value) { |
3986 DCHECK(index >= 0 && index < this->length()); | 4001 DCHECK(index >= 0 && index < this->length()); |
3987 WRITE_BYTE_FIELD(this, kHeaderSize + index * kCharSize, value); | 4002 WRITE_BYTE_FIELD(this, kHeaderSize + index * kCharSize, value); |
3988 } | 4003 } |
3989 | 4004 |
3990 void ByteArray::copy_in(int index, const byte* buffer, int length) { | 4005 void ByteArray::copy_in(int index, const byte* buffer, int length) { |
3991 DCHECK(index >= 0 && length >= 0 && index + length >= index && | 4006 DCHECK(index >= 0 && length >= 0 && index + length >= index && |
3992 index + length <= this->length()); | 4007 index + length <= this->length()); |
3993 byte* dst_addr = FIELD_ADDR(this, kHeaderSize + index * kCharSize); | 4008 byte* dst_addr = FIELD_ADDR(this, kHeaderSize + index * kCharSize); |
(...skipping 4029 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
8023 #undef WRITE_INT64_FIELD | 8038 #undef WRITE_INT64_FIELD |
8024 #undef READ_BYTE_FIELD | 8039 #undef READ_BYTE_FIELD |
8025 #undef WRITE_BYTE_FIELD | 8040 #undef WRITE_BYTE_FIELD |
8026 #undef NOBARRIER_READ_BYTE_FIELD | 8041 #undef NOBARRIER_READ_BYTE_FIELD |
8027 #undef NOBARRIER_WRITE_BYTE_FIELD | 8042 #undef NOBARRIER_WRITE_BYTE_FIELD |
8028 | 8043 |
8029 } // namespace internal | 8044 } // namespace internal |
8030 } // namespace v8 | 8045 } // namespace v8 |
8031 | 8046 |
8032 #endif // V8_OBJECTS_INL_H_ | 8047 #endif // V8_OBJECTS_INL_H_ |
OLD | NEW |