Bug 1203140 - Add a pref cache for the touch events pref, as it can get called a lot. r=smaug
authorKartikaya Gupta <kgupta@mozilla.com>
Tue, 24 May 2016 11:24:30 -0400
changeset 298803 d4ea3b7f6bacd0657a4347934f0f7714893b7ea3
parent 298802 16b370b80a93eaf19a255945002c9a0c617c76db
child 298804 1c1effae71466d6da3bd3c22baa34910973ce52c
push id30285
push usercbook@mozilla.com
push dateWed, 25 May 2016 13:06:07 +0000
treeherdermozilla-central@d6d4e8417d2f [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerssmaug
bugs1203140
milestone49.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 1203140 - Add a pref cache for the touch events pref, as it can get called a lot. r=smaug MozReview-Commit-ID: EQD3oxFaInO
dom/events/TouchEvent.cpp
--- a/dom/events/TouchEvent.cpp
+++ b/dom/events/TouchEvent.cpp
@@ -160,38 +160,43 @@ TouchEvent::ChangedTouches()
   }
   return mChangedTouches;
 }
 
 // static
 bool
 TouchEvent::PrefEnabled(JSContext* aCx, JSObject* aGlobal)
 {
+  static bool sPrefCached = false;
+  static int32_t sPrefCacheValue = 0;
+
+  if (!sPrefCached) {
+    sPrefCached = true;
+    Preferences::AddIntVarCache(&sPrefCacheValue, "dom.w3c_touch_events.enabled");
+  }
+
   bool prefValue = false;
-  int32_t flag = 0;
-  if (NS_SUCCEEDED(Preferences::GetInt("dom.w3c_touch_events.enabled", &flag))) {
-    if (flag == 2) {
+  if (sPrefCacheValue == 2) {
 #if defined(MOZ_B2G) || defined(MOZ_WIDGET_ANDROID)
-      // Touch support is always enabled on B2G and android.
-      prefValue = true;
+    // Touch support is always enabled on B2G and android.
+    prefValue = true;
 #elif defined(XP_WIN) || MOZ_WIDGET_GTK == 3
-      static bool sDidCheckTouchDeviceSupport = false;
-      static bool sIsTouchDeviceSupportPresent = false;
-      // On Windows and GTK3 we auto-detect based on device support.
-      if (!sDidCheckTouchDeviceSupport) {
-        sDidCheckTouchDeviceSupport = true;
-        sIsTouchDeviceSupportPresent = WidgetUtils::IsTouchDeviceSupportPresent();
-      }
-      prefValue = sIsTouchDeviceSupportPresent;
+    static bool sDidCheckTouchDeviceSupport = false;
+    static bool sIsTouchDeviceSupportPresent = false;
+    // On Windows and GTK3 we auto-detect based on device support.
+    if (!sDidCheckTouchDeviceSupport) {
+      sDidCheckTouchDeviceSupport = true;
+      sIsTouchDeviceSupportPresent = WidgetUtils::IsTouchDeviceSupportPresent();
+    }
+    prefValue = sIsTouchDeviceSupportPresent;
 #else
-      prefValue = false;
+    prefValue = false;
 #endif
-    } else {
-      prefValue = !!flag;
-    }
+  } else {
+    prefValue = !!sPrefCacheValue;
   }
   if (prefValue) {
     nsContentUtils::InitializeTouchEventTable();
   }
   return prefValue;
 }
 
 // static