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 2289 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2300 | 2300 |
2301 Object* FixedArray::get(int index) const { | 2301 Object* FixedArray::get(int index) const { |
2302 SLOW_DCHECK(index >= 0 && index < this->length()); | 2302 SLOW_DCHECK(index >= 0 && index < this->length()); |
2303 return READ_FIELD(this, kHeaderSize + index * kPointerSize); | 2303 return READ_FIELD(this, kHeaderSize + index * kPointerSize); |
2304 } | 2304 } |
2305 | 2305 |
2306 Handle<Object> FixedArray::get(FixedArray* array, int index, Isolate* isolate) { | 2306 Handle<Object> FixedArray::get(FixedArray* array, int index, Isolate* isolate) { |
2307 return handle(array->get(index), isolate); | 2307 return handle(array->get(index), isolate); |
2308 } | 2308 } |
2309 | 2309 |
| 2310 template <class T> |
| 2311 MaybeHandle<T> FixedArray::GetValueOrNull(int index) const { |
| 2312 Object* obj = get(index); |
| 2313 if (obj->IsUndefined(GetIsolate())) return MaybeHandle<T>(); |
| 2314 return Handle<T>(T::cast(obj)); |
| 2315 } |
| 2316 |
| 2317 template <class T> |
| 2318 Handle<T> FixedArray::GetValue(int index) const { |
| 2319 Object* obj = get(index); |
| 2320 CHECK(!obj->IsUndefined(GetIsolate())); |
| 2321 return Handle<T>(T::cast(obj)); |
| 2322 } |
2310 | 2323 |
2311 bool FixedArray::is_the_hole(int index) { | 2324 bool FixedArray::is_the_hole(int index) { |
2312 return get(index) == GetHeap()->the_hole_value(); | 2325 return get(index) == GetHeap()->the_hole_value(); |
2313 } | 2326 } |
2314 | 2327 |
2315 | |
2316 void FixedArray::set(int index, Smi* value) { | 2328 void FixedArray::set(int index, Smi* value) { |
2317 DCHECK(map() != GetHeap()->fixed_cow_array_map()); | 2329 DCHECK(map() != GetHeap()->fixed_cow_array_map()); |
2318 DCHECK(index >= 0 && index < this->length()); | 2330 DCHECK(index >= 0 && index < this->length()); |
2319 DCHECK(reinterpret_cast<Object*>(value)->IsSmi()); | 2331 DCHECK(reinterpret_cast<Object*>(value)->IsSmi()); |
2320 int offset = kHeaderSize + index * kPointerSize; | 2332 int offset = kHeaderSize + index * kPointerSize; |
2321 WRITE_FIELD(this, offset, value); | 2333 WRITE_FIELD(this, offset, value); |
2322 } | 2334 } |
2323 | 2335 |
2324 | 2336 |
2325 void FixedArray::set(int index, Object* value) { | 2337 void FixedArray::set(int index, Object* value) { |
(...skipping 1627 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3953 } | 3965 } |
3954 | 3966 |
3955 | 3967 |
3956 int ByteArray::Size() { return RoundUp(length() + kHeaderSize, kPointerSize); } | 3968 int ByteArray::Size() { return RoundUp(length() + kHeaderSize, kPointerSize); } |
3957 | 3969 |
3958 byte ByteArray::get(int index) { | 3970 byte ByteArray::get(int index) { |
3959 DCHECK(index >= 0 && index < this->length()); | 3971 DCHECK(index >= 0 && index < this->length()); |
3960 return READ_BYTE_FIELD(this, kHeaderSize + index * kCharSize); | 3972 return READ_BYTE_FIELD(this, kHeaderSize + index * kCharSize); |
3961 } | 3973 } |
3962 | 3974 |
| 3975 const byte* ByteArray::data() const { |
| 3976 return reinterpret_cast<const byte*>(FIELD_ADDR_CONST(this, kHeaderSize)); |
| 3977 } |
3963 | 3978 |
3964 void ByteArray::set(int index, byte value) { | 3979 void ByteArray::set(int index, byte value) { |
3965 DCHECK(index >= 0 && index < this->length()); | 3980 DCHECK(index >= 0 && index < this->length()); |
3966 WRITE_BYTE_FIELD(this, kHeaderSize + index * kCharSize, value); | 3981 WRITE_BYTE_FIELD(this, kHeaderSize + index * kCharSize, value); |
3967 } | 3982 } |
3968 | 3983 |
3969 void ByteArray::copy_in(int index, const byte* buffer, int length) { | 3984 void ByteArray::copy_in(int index, const byte* buffer, int length) { |
3970 DCHECK(index >= 0 && length >= 0 && index + length >= index && | 3985 DCHECK(index >= 0 && length >= 0 && index + length >= index && |
3971 index + length <= this->length()); | 3986 index + length <= this->length()); |
3972 byte* dst_addr = FIELD_ADDR(this, kHeaderSize + index * kCharSize); | 3987 byte* dst_addr = FIELD_ADDR(this, kHeaderSize + index * kCharSize); |
(...skipping 3984 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
7957 #undef WRITE_INT64_FIELD | 7972 #undef WRITE_INT64_FIELD |
7958 #undef READ_BYTE_FIELD | 7973 #undef READ_BYTE_FIELD |
7959 #undef WRITE_BYTE_FIELD | 7974 #undef WRITE_BYTE_FIELD |
7960 #undef NOBARRIER_READ_BYTE_FIELD | 7975 #undef NOBARRIER_READ_BYTE_FIELD |
7961 #undef NOBARRIER_WRITE_BYTE_FIELD | 7976 #undef NOBARRIER_WRITE_BYTE_FIELD |
7962 | 7977 |
7963 } // namespace internal | 7978 } // namespace internal |
7964 } // namespace v8 | 7979 } // namespace v8 |
7965 | 7980 |
7966 #endif // V8_OBJECTS_INL_H_ | 7981 #endif // V8_OBJECTS_INL_H_ |
OLD | NEW |