Bug 701863 - make JS/C++ divide explicit; r=taras
authorNathan Froyd <froydnj@mozilla.com>
Fri, 06 Jan 2012 14:39:29 -0500
changeset 85184 b9601344d6d7419e03f7c39e7b394c257aca3217
parent 85183 309fc0271e4c0c287045e34d9435c0ace686ad05
child 85185 4c6086b7e2fab725f2d3b3b77d575cd028029beb
push id805
push userakeybl@mozilla.com
push dateWed, 01 Feb 2012 18:17:35 +0000
treeherdermozilla-aurora@6fb3bf232436 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerstaras
bugs701863
milestone12.0a1
Bug 701863 - make JS/C++ divide explicit; r=taras
toolkit/components/telemetry/Telemetry.cpp
--- a/toolkit/components/telemetry/Telemetry.cpp
+++ b/toolkit/components/telemetry/Telemetry.cpp
@@ -79,16 +79,18 @@ public:
     PRUint32 hitCount;
     PRUint32 totalTime;
   };
   typedef nsBaseHashtableET<nsCStringHashKey, StmtStats> SlowSQLEntryType;
 
 private:
   bool AddSQLInfo(JSContext *cx, JSObject *rootObj, bool mainThread);
 
+  // Like GetHistogramById, but returns the underlying C++ object, not the JS one.
+  nsresult GetHistogramByName(const nsACString &name, Histogram **ret);
   // This is used for speedy JS string->Telemetry::ID conversions
   typedef nsBaseHashtableET<nsCharPtrHashKey, Telemetry::ID> CharPtrEntryType;
   typedef nsTHashtable<CharPtrEntryType> HistogramMapType;
   HistogramMapType mHistogramMap;
   bool mCanRecord;
   static TelemetryImpl *sTelemetry;
   nsTHashtable<SlowSQLEntryType> mSlowSQLOnMainThread;
   nsTHashtable<SlowSQLEntryType> mSlowSQLOnOtherThread;
@@ -384,16 +386,43 @@ TelemetryImpl::AddSQLInfo(JSContext *cx,
                                           static_cast<void*>(&args));
   if (num != sqlMap->Count())
     return false;
 
   return true;
 }
 
 
+nsresult
+TelemetryImpl::GetHistogramByName(const nsACString &name, Histogram **ret)
+{
+  // Cache names
+  // Note the histogram names are statically allocated
+  if (!mHistogramMap.Count()) {
+    for (PRUint32 i = 0; i < Telemetry::HistogramCount; i++) {
+      CharPtrEntryType *entry = mHistogramMap.PutEntry(gHistograms[i].id);
+      if (NS_UNLIKELY(!entry)) {
+        mHistogramMap.Clear();
+        return NS_ERROR_OUT_OF_MEMORY;
+      }
+      entry->mData = (Telemetry::ID) i;
+    }
+  }
+
+  CharPtrEntryType *entry = mHistogramMap.GetEntry(PromiseFlatCString(name).get());
+  if (!entry)
+    return NS_ERROR_FAILURE;
+
+  nsresult rv = GetHistogramByEnumId(entry->mData, ret);
+  if (NS_FAILED(rv))
+    return rv;
+
+  return NS_OK;
+}
+
 NS_IMETHODIMP
 TelemetryImpl::GetHistogramSnapshots(JSContext *cx, jsval *ret)
 {
   JSObject *root_obj = JS_NewObject(cx, NULL, NULL, NULL);
   if (!root_obj)
     return NS_ERROR_FAILURE;
   *ret = OBJECT_TO_JSVAL(root_obj);
 
@@ -429,36 +458,18 @@ TelemetryImpl::GetSlowSQL(JSContext *cx,
     return NS_ERROR_FAILURE;
 
   return NS_OK;
 }
 
 NS_IMETHODIMP
 TelemetryImpl::GetHistogramById(const nsACString &name, JSContext *cx, jsval *ret)
 {
-  // Cache names
-  // Note the histogram names are statically allocated
-  if (!mHistogramMap.Count()) {
-    for (PRUint32 i = 0; i < Telemetry::HistogramCount; i++) {
-      CharPtrEntryType *entry = mHistogramMap.PutEntry(gHistograms[i].id);
-      if (NS_UNLIKELY(!entry)) {
-        mHistogramMap.Clear();
-        return NS_ERROR_OUT_OF_MEMORY;
-      }
-      entry->mData = (Telemetry::ID) i;
-    }
-  }
-
-  CharPtrEntryType *entry = mHistogramMap.GetEntry(PromiseFlatCString(name).get());
-  if (!entry)
-    return NS_ERROR_FAILURE;
-  
   Histogram *h;
-
-  nsresult rv = GetHistogramByEnumId(entry->mData, &h);
+  nsresult rv = GetHistogramByName(name, &h);
   if (NS_FAILED(rv))
     return rv;
 
   return WrapAndReturnHistogram(h, cx, ret);
 }
 
 NS_IMETHODIMP
 TelemetryImpl::GetCanRecord(bool *ret) {