Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(200)

Unified Diff: src/field-index-inl.h

Issue 300283002: Introduce FieldIndex to unify and abstract property/field offset (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Fix mutable boxed double runtime function Created 6 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « src/field-index.cc ('k') | src/heap-snapshot-generator.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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..dd13709c78708b69e03e381175846f5e83164e25
--- /dev/null
+++ b/src/field-index-inl.h
@@ -0,0 +1,80 @@
+// 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);
+ }
+ int first_inobject_offset = map->GetInObjectPropertyOffset(0);
+ if (offset < first_inobject_offset) {
+ return FieldIndex(true, index, false, 0, 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 first_inobject_offset;
+ if (is_inobject) {
+ first_inobject_offset = map->GetInObjectPropertyOffset(0);
+ } else {
+ first_inobject_offset = FixedArray::kHeaderSize;
+ property_index -= inobject_properties;
+ }
+ return FieldIndex(is_inobject,
+ property_index + first_inobject_offset / kPointerSize,
+ is_double, inobject_properties, first_inobject_offset);
+}
+
+
+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 first_inobject_offset = 0;
+ field_index >>= 1;
+ if (field_index < 0) {
+ field_index = -(field_index + 1);
+ is_inobject = false;
+ first_inobject_offset = FixedArray::kHeaderSize;
+ field_index += FixedArray::kHeaderSize / kPointerSize;
+ } else {
+ first_inobject_offset = map->GetInObjectPropertyOffset(0);
+ field_index += JSObject::kHeaderSize / kPointerSize;
+ }
+ return FieldIndex(is_inobject, field_index, is_double,
+ map->inobject_properties(), first_inobject_offset);
+}
+
+
+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
« no previous file with comments | « src/field-index.cc ('k') | src/heap-snapshot-generator.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698