Bug 739510. JSObjectBuilder: Speed up construction of char * properties. r=ehsan
authorJeff Muizelaar <jmuizelaar@mozilla.com>
Mon, 26 Mar 2012 23:35:28 -0400
changeset 95546 5130ac1fa079c536c1a265d9842eaca52faa3546
parent 95545 0d0ac6a97737209b487ba276b97f3d102363603d
child 95547 8c3acc1224692cf4ef8a741ef2d8af88e502f7a9
push id160
push userlsblakk@mozilla.com
push dateFri, 13 Jul 2012 18:18:57 +0000
treeherdermozilla-release@228ba1a111fc [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersehsan
bugs739510
milestone14.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 739510. JSObjectBuilder: Speed up construction of char * properties. r=ehsan This eliminates two additional copies: NS_ConvertASCIItoUTF16 and PromiseFlatString by constructing the JSString directly. It is also designed so that literal strings will have their strlen computed at compile time.
tools/profiler/JSObjectBuilder.h
--- a/tools/profiler/JSObjectBuilder.h
+++ b/tools/profiler/JSObjectBuilder.h
@@ -79,20 +79,33 @@ class JSObjectBuilder
       mOk = JS_FALSE;
 
     if (!mOk)
       return;
 
     mOk = JS_DefineProperty(mCx, aObject, name, STRING_TO_JSVAL(string), NULL, NULL, JSPROP_ENUMERATE);
   }
 
+  void DefineProperty(JSObject *aObject, const char *name, const char *value, size_t valueLength)
+  {
+    if (!mOk)
+      return;
+
+    JSString *string = JS_NewStringCopyN(mCx, value, valueLength);
+    if (!string) {
+      mOk = JS_FALSE;
+      return;
+    }
+
+    mOk = JS_DefineProperty(mCx, aObject, name, STRING_TO_JSVAL(string), NULL, NULL, JSPROP_ENUMERATE);
+  }
+
   void DefineProperty(JSObject *aObject, const char *name, const char *value)
   {
-    nsAutoString string = NS_ConvertASCIItoUTF16(value);
-    DefineProperty(aObject, name, string);
+    DefineProperty(aObject, name, value, strlen(value));
   }
 
   void ArrayPush(JSObject *aArray, int value)
   {
     if (!mOk)
       return;
 
     jsval objval = INT_TO_JSVAL(value);