Add some inline property data to Object
authorLars Knoll <lars.knoll@digia.com>
Mon, 15 Apr 2013 08:31:35 +0000 (10:31 +0200)
committerSimon Hausmann <simon.hausmann@digia.com>
Mon, 15 Apr 2013 09:01:05 +0000 (11:01 +0200)
This avoids malloc'ing the memberData array in most cases, and
speed up the V8 benchmark by another 10%

Change-Id: Id5976a9f9b389ee2d1568211b486c2896d818dd3
Reviewed-by: Simon Hausmann <simon.hausmann@digia.com>
src/v4/qv4object.cpp
src/v4/qv4object.h

index f82b8bf..5091ceb 100644 (file)
@@ -69,7 +69,7 @@ DEFINE_MANAGED_VTABLE(Object);
 Object::Object(ExecutionEngine *engine)
     : prototype(0)
     , internalClass(engine->emptyClass)
-    , memberDataAlloc(0), memberData(0)
+    , memberDataAlloc(InlinePropertySize), memberData(inlineProperties)
     , arrayOffset(0), arrayDataLen(0), arrayAlloc(0), arrayAttributes(0), arrayData(0), sparseArray(0)
     , externalResource(0)
 {
@@ -80,7 +80,7 @@ Object::Object(ExecutionEngine *engine)
 Object::Object(ExecutionContext *context)
     : prototype(0)
     , internalClass(context->engine->emptyClass)
-    , memberDataAlloc(0), memberData(0)
+    , memberDataAlloc(InlinePropertySize), memberData(inlineProperties)
     , arrayOffset(0), arrayDataLen(0), arrayAlloc(0), arrayAttributes(0), arrayData(0), sparseArray(0)
     , externalResource(0)
 {
@@ -91,7 +91,8 @@ Object::Object(ExecutionContext *context)
 Object::~Object()
 {
     delete externalResource;
-    delete [] memberData;
+    if (memberData != inlineProperties)
+        delete [] memberData;
     delete [] (arrayData - (sparseArray ? 0 : arrayOffset));
     if (arrayAttributes)
         delete [] (arrayAttributes - (sparseArray ? 0 : arrayOffset));
@@ -229,7 +230,8 @@ Property *Object::insertMember(String *s, PropertyAttributes attributes)
         memberDataAlloc = qMax((uint)8, 2*memberDataAlloc);
         Property *newMemberData = new Property[memberDataAlloc];
         memcpy(newMemberData, memberData, sizeof(Property)*idx);
-        delete [] memberData;
+        if (memberData != inlineProperties)
+            delete [] memberData;
         memberData = newMemberData;
     }
     return memberData + idx;
index 226c005..d1bac5f 100644 (file)
@@ -124,6 +124,11 @@ struct Q_V4_EXPORT Object: Managed {
     SparseArray *sparseArray;
     ExternalResource *externalResource;
 
+    enum {
+        InlinePropertySize = 4
+    };
+    Property inlineProperties[InlinePropertySize];
+
     Object(ExecutionEngine *engine);
     Object(ExecutionContext *context);
     ~Object();