Index: src/field-index-inl.h |
diff --git a/src/field-index-inl.h b/src/field-index-inl.h |
new file mode 100644 |
index 0000000000000000000000000000000000000000..19565135fa6be776b8714aba547ed1cdeb462a09 |
--- /dev/null |
+++ b/src/field-index-inl.h |
@@ -0,0 +1,81 @@ |
+// Copyright 2014 the V8 project authors. All rights reserved. |
+// Use of this source code is governed by a BSD-style license that can be |
+// found in the LICENSE file. |
+ |
+#ifndef V8_FIELD_INDEX_INL_H_ |
+#define V8_FIELD_INDEX_INL_H_ |
+ |
+#include "src/field-index.h" |
+ |
+namespace v8 { |
+namespace internal { |
+ |
+ |
+inline FieldIndex FieldIndex::ForInObjectOffset(int offset, Map* map) { |
+ ASSERT((offset % kPointerSize) == 0); |
+ int index = offset / kPointerSize; |
+ if (map == NULL) { |
+ 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
|
+ } |
+ int first_inobject_offset = map->instance_size() - |
+ (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.
|
+ if (offset < first_inobject_offset) { |
+ return FieldIndex(true, index, false, index + 1, 0, true); |
+ } else { |
+ return FieldIndex::ForPropertyIndex(map, offset / kPointerSize); |
+ } |
+} |
+ |
+ |
+inline FieldIndex FieldIndex::ForPropertyIndex(Map* map, |
+ int property_index, |
+ bool is_double) { |
+ ASSERT(map->instance_type() >= FIRST_NONSTRING_TYPE); |
+ int inobject_properties = map->inobject_properties(); |
+ bool is_inobject = property_index < inobject_properties; |
+ int header_size; |
+ if (is_inobject) { |
+ header_size = map->instance_size() - kPointerSize * inobject_properties; |
+ } else { |
+ header_size = FixedArray::kHeaderSize; |
+ property_index -= inobject_properties; |
+ } |
+ return FieldIndex(is_inobject, property_index + header_size / kPointerSize, |
+ is_double, inobject_properties, header_size); |
+} |
+ |
+ |
+inline FieldIndex FieldIndex::ForLoadByFieldIndex(Map* map, int orig_index) { |
+ int field_index = orig_index; |
+ int is_inobject = true; |
+ bool is_double = field_index & 1; |
+ int header_size = 0; |
+ field_index >>= 1; |
+ if (field_index < 0) { |
+ field_index = -(field_index + 1); |
+ is_inobject = false; |
+ header_size = FixedArray::kHeaderSize; |
+ field_index += FixedArray::kHeaderSize / kPointerSize; |
+ } else { |
+ header_size = map->instance_size() - kPointerSize * |
+ map->inobject_properties(); |
+ field_index += JSObject::kHeaderSize / kPointerSize; |
+ } |
+ return FieldIndex(is_inobject, field_index, is_double, |
+ map->inobject_properties(), header_size); |
+} |
+ |
+ |
+inline FieldIndex FieldIndex::ForDescriptor(Map* map, int descriptor_index) { |
+ PropertyDetails details = |
+ map->instance_descriptors()->GetDetails(descriptor_index); |
+ int field_index = |
+ map->instance_descriptors()->GetFieldIndex(descriptor_index); |
+ return ForPropertyIndex(map, field_index, |
+ details.representation().IsDouble()); |
+} |
+ |
+ |
+} } // namespace v8::internal |
+ |
+#endif |