OLD | NEW |
---|---|
(Empty) | |
1 // Copyright 2014 the V8 project authors. All rights reserved. | |
2 // Use of this source code is governed by a BSD-style license that can be | |
3 // found in the LICENSE file. | |
4 | |
5 #ifndef V8_FIELD_INDEX_INL_H_ | |
6 #define V8_FIELD_INDEX_INL_H_ | |
7 | |
8 #include "src/field-index.h" | |
9 | |
10 namespace v8 { | |
11 namespace internal { | |
12 | |
13 | |
14 inline FieldIndex FieldIndex::ForInObjectOffset(int offset, Map* map) { | |
15 ASSERT((offset % kPointerSize) == 0); | |
16 int index = offset / kPointerSize; | |
17 if (map == NULL) { | |
18 return FieldIndex(true, index, false, index + 1, 0, true); | |
Toon Verwaest
2014/06/06 12:00:33
Since you have the map, what about just calculatin
danno
2014/06/06 14:09:57
In this case, we don't have the map (it's NULL). T
| |
19 } | |
20 int first_inobject_offset = map->instance_size() - | |
21 (map->inobject_properties() * kPointerSize); | |
Toon Verwaest
2014/06/06 12:00:33
What about a helper method: first_inobject_offset(
danno
2014/06/06 14:09:57
Done.
| |
22 if (offset < first_inobject_offset) { | |
23 return FieldIndex(true, index, false, index + 1, 0, true); | |
24 } else { | |
25 return FieldIndex::ForPropertyIndex(map, offset / kPointerSize); | |
26 } | |
27 } | |
28 | |
29 | |
30 inline FieldIndex FieldIndex::ForPropertyIndex(Map* map, | |
31 int property_index, | |
32 bool is_double) { | |
33 ASSERT(map->instance_type() >= FIRST_NONSTRING_TYPE); | |
34 int inobject_properties = map->inobject_properties(); | |
35 bool is_inobject = property_index < inobject_properties; | |
36 int header_size; | |
37 if (is_inobject) { | |
38 header_size = map->instance_size() - kPointerSize * inobject_properties; | |
39 } else { | |
40 header_size = FixedArray::kHeaderSize; | |
41 property_index -= inobject_properties; | |
42 } | |
43 return FieldIndex(is_inobject, property_index + header_size / kPointerSize, | |
44 is_double, inobject_properties, header_size); | |
45 } | |
46 | |
47 | |
48 inline FieldIndex FieldIndex::ForLoadByFieldIndex(Map* map, int orig_index) { | |
49 int field_index = orig_index; | |
50 int is_inobject = true; | |
51 bool is_double = field_index & 1; | |
52 int header_size = 0; | |
53 field_index >>= 1; | |
54 if (field_index < 0) { | |
55 field_index = -(field_index + 1); | |
56 is_inobject = false; | |
57 header_size = FixedArray::kHeaderSize; | |
58 field_index += FixedArray::kHeaderSize / kPointerSize; | |
59 } else { | |
60 header_size = map->instance_size() - kPointerSize * | |
61 map->inobject_properties(); | |
62 field_index += JSObject::kHeaderSize / kPointerSize; | |
63 } | |
64 return FieldIndex(is_inobject, field_index, is_double, | |
65 map->inobject_properties(), header_size); | |
66 } | |
67 | |
68 | |
69 inline FieldIndex FieldIndex::ForDescriptor(Map* map, int descriptor_index) { | |
70 PropertyDetails details = | |
71 map->instance_descriptors()->GetDetails(descriptor_index); | |
72 int field_index = | |
73 map->instance_descriptors()->GetFieldIndex(descriptor_index); | |
74 return ForPropertyIndex(map, field_index, | |
75 details.representation().IsDouble()); | |
76 } | |
77 | |
78 | |
79 } } // namespace v8::internal | |
80 | |
81 #endif | |
OLD | NEW |