Reviewers: Mads Ager, Kasper Lund,

Description:
Expose conversion of objects with prototype chain into fast mode.

That would be used in DOM bindings to turn common prototypes into
fast mode and thus enable various optimizations.


Please review this at http://codereview.chromium.org/149452

SVN Base: http://v8.googlecode.com/svn/branches/bleeding_edge/

Affected files:
   M     include/v8.h
   M     src/api.cc
   M     src/objects.h
   M     src/objects.cc


Index: include/v8.h
===================================================================
--- include/v8.h        (revision 2423)
+++ include/v8.h        (working copy)
@@ -1162,6 +1162,12 @@
     */
    Local<Object> Clone();

+  /**
+   * Attempts to optimize the object for the case if its property set
+   * won't change anymore.
+   */
+  Local<Object> Optimize();
+
    static Local<Object> New();
    static Object* Cast(Value* obj);
   private:
Index: src/api.cc
===================================================================
--- src/api.cc  (revision 2423)
+++ src/api.cc  (working copy)
@@ -2111,6 +2111,17 @@
  }


+Local<v8::Object> v8::Object::Optimize() {
+  ON_BAILOUT("v8::Object::Optimize()", return Local<Object>());
+  ENTER_V8;
+  i::Handle<i::JSObject> self = Utils::OpenHandle(this);
+  i::Object* result_object =  
self->TransformToFastPropertiesWithProtoChain();
+  if (result_object->IsFailure()) return Local<Object>();
+  i::Handle<i::JSObject> result(i::JSObject::cast(result_object));
+  return Utils::ToLocal(result);
+}
+
+
  int v8::Object::GetIdentityHash() {
    ON_BAILOUT("v8::Object::GetIdentityHash()", return 0);
    ENTER_V8;
Index: src/objects.cc
===================================================================
--- src/objects.cc      (revision 2423)
+++ src/objects.cc      (working copy)
@@ -2225,6 +2225,26 @@
  }


+Object* JSObject::TransformToFastPropertiesWithProtoChain() {
+  const int unusedPropertyFields = 0;
+  Object* transformed = TransformToFastProperties(unusedPropertyFields);
+  if (transformed->IsFailure()) return transformed;
+
+  JSObject* previous = JSObject::cast(transformed);
+  while (true) {
+    Object* proto = previous->GetPrototype();
+    if (proto->IsNull()) return transformed;
+
+    Object* transformed_proto =
+         
JSObject::cast(proto)->TransformToFastProperties(unusedPropertyFields);
+    if (transformed_proto->IsFailure()) return transformed_proto;
+
+    previous->map()->set_prototype(transformed_proto);
+    previous = JSObject::cast(transformed_proto);
+  }
+}
+
+
  Object* JSObject::NormalizeElements() {
    if (!HasFastElements()) return this;

Index: src/objects.h
===================================================================
--- src/objects.h       (revision 2423)
+++ src/objects.h       (working copy)
@@ -1589,6 +1589,11 @@
    // Returns failure if allocation failed.
    Object* TransformToFastProperties(int unused_property_fields);

+  // Transform slow named properties to fast variants for
+  // the object and its prototype chain.
+  // Returns failure if allocation failed.
+  Object* TransformToFastPropertiesWithProtoChain();
+
    // Access fast-case object properties at index.
    inline Object* FastPropertyAt(int index);
    inline Object* FastPropertyAtPut(int index, Object* value);



--~--~---------~--~----~------------~-------~--~----~
v8-dev mailing list
[email protected]
http://groups.google.com/group/v8-dev
-~----------~----~----~----~------~----~------~--~---

Reply via email to