Bug 1036290 Use nsAutoTArray at copying WidgetTouchEvent::TouchArray r=roc
authorMasayuki Nakano <masayuki@d-toybox.com>
Thu, 10 Jul 2014 01:17:05 +0900
changeset 193194 19663c22e7eb1d0bd8a2d4f84e1f36da8f2da0d8
parent 193193 764a33b3eca81c89cf4ac10c77af783a82ee001f
child 193195 0ed88d692f42f34802beafcea77797f61c918155
push id27112
push usercbook@mozilla.com
push dateThu, 10 Jul 2014 12:47:23 +0000
treeherdermozilla-central@6e9f72bdd32e [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersroc
bugs1036290
milestone33.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 1036290 Use nsAutoTArray at copying WidgetTouchEvent::TouchArray r=roc
dom/events/TouchEvent.cpp
dom/events/TouchEvent.h
layout/base/nsPresShell.cpp
widget/TouchEvents.h
--- a/dom/events/TouchEvent.cpp
+++ b/dom/events/TouchEvent.cpp
@@ -123,17 +123,17 @@ TouchEvent::InitTouchEvent(const nsAStri
 
 TouchList*
 TouchEvent::Touches()
 {
   if (!mTouches) {
     WidgetTouchEvent* touchEvent = mEvent->AsTouchEvent();
     if (mEvent->message == NS_TOUCH_END || mEvent->message == NS_TOUCH_CANCEL) {
       // for touchend events, remove any changed touches from the touches array
-      WidgetTouchEvent::TouchArray unchangedTouches;
+      WidgetTouchEvent::AutoTouchArray unchangedTouches;
       const WidgetTouchEvent::TouchArray& touches = touchEvent->touches;
       for (uint32_t i = 0; i < touches.Length(); ++i) {
         if (!touches[i]->mChanged) {
           unchangedTouches.AppendElement(touches[i]);
         }
       }
       mTouches = new TouchList(ToSupports(this), unchangedTouches);
     } else {
@@ -142,17 +142,17 @@ TouchEvent::Touches()
   }
   return mTouches;
 }
 
 TouchList*
 TouchEvent::TargetTouches()
 {
   if (!mTargetTouches) {
-    nsTArray< nsRefPtr<Touch> > targetTouches;
+    WidgetTouchEvent::AutoTouchArray targetTouches;
     WidgetTouchEvent* touchEvent = mEvent->AsTouchEvent();
     const WidgetTouchEvent::TouchArray& touches = touchEvent->touches;
     for (uint32_t i = 0; i < touches.Length(); ++i) {
       // for touchend/cancel events, don't append to the target list if this is a
       // touch that is ending
       if ((mEvent->message != NS_TOUCH_END &&
            mEvent->message != NS_TOUCH_CANCEL) || !touches[i]->mChanged) {
         if (touches[i]->mTarget == mEvent->originalTarget) {
@@ -164,17 +164,17 @@ TouchEvent::TargetTouches()
   }
   return mTargetTouches;
 }
 
 TouchList*
 TouchEvent::ChangedTouches()
 {
   if (!mChangedTouches) {
-    nsTArray< nsRefPtr<Touch> > changedTouches;
+    WidgetTouchEvent::AutoTouchArray changedTouches;
     WidgetTouchEvent* touchEvent = mEvent->AsTouchEvent();
     const WidgetTouchEvent::TouchArray& touches = touchEvent->touches;
     for (uint32_t i = 0; i < touches.Length(); ++i) {
       if (touches[i]->mChanged) {
         changedTouches.AppendElement(touches[i]);
       }
     }
     mChangedTouches = new TouchList(ToSupports(this), changedTouches);
--- a/dom/events/TouchEvent.h
+++ b/dom/events/TouchEvent.h
@@ -5,18 +5,18 @@
 #ifndef mozilla_dom_TouchEvent_h_
 #define mozilla_dom_TouchEvent_h_
 
 #include "mozilla/dom/Touch.h"
 #include "mozilla/dom/TouchEventBinding.h"
 #include "mozilla/dom/UIEvent.h"
 #include "mozilla/Attributes.h"
 #include "mozilla/EventForwards.h"
+#include "mozilla/TouchEvents.h"
 #include "nsJSEnvironment.h"
-#include "nsTArray.h"
 #include "nsWrapperCache.h"
 
 class nsAString;
 
 namespace mozilla {
 namespace dom {
 
 class TouchList MOZ_FINAL : public nsISupports
@@ -28,17 +28,17 @@ public:
 
   TouchList(nsISupports* aParent)
     : mParent(aParent)
   {
     SetIsDOMBinding();
     nsJSContext::LikelyShortLivingObjectCreated();
   }
   TouchList(nsISupports* aParent,
-            const nsTArray<nsRefPtr<Touch> >& aTouches)
+            const WidgetTouchEvent::TouchArray& aTouches)
     : mParent(aParent)
     , mPoints(aTouches)
   {
     SetIsDOMBinding();
     nsJSContext::LikelyShortLivingObjectCreated();
   }
 
   void Append(Touch* aPoint)
@@ -73,17 +73,17 @@ public:
     return mPoints[aIndex];
   }
   Touch* IdentifiedTouch(int32_t aIdentifier) const;
 
 protected:
   ~TouchList() {}
 
   nsCOMPtr<nsISupports> mParent;
-  nsTArray<nsRefPtr<Touch> > mPoints;
+  WidgetTouchEvent::TouchArray mPoints;
 };
 
 class TouchEvent : public UIEvent
 {
 public:
   TouchEvent(EventTarget* aOwner,
              nsPresContext* aPresContext,
              WidgetTouchEvent* aEvent);
--- a/layout/base/nsPresShell.cpp
+++ b/layout/base/nsPresShell.cpp
@@ -6625,17 +6625,17 @@ AppendToTouchList(const uint32_t& aKey, 
   aData->mChanged = false;
   touches->AppendElement(aData);
   return PL_DHASH_NEXT;
 }
 
 void
 PresShell::EvictTouches()
 {
-  WidgetTouchEvent::TouchArray touches;
+  WidgetTouchEvent::AutoTouchArray touches;
   gCaptureTouchList->Enumerate(&AppendToTouchList, &touches);
   for (uint32_t i = 0; i < touches.Length(); ++i) {
     EvictTouchPoint(touches[i], mDocument);
   }
 }
 
 static PLDHashOperator
 FindAnyTarget(const uint32_t& aKey, nsRefPtr<dom::Touch>& aData,
@@ -7569,17 +7569,17 @@ PresShell::HandleEventInternal(WidgetEve
         isHandlingUserInput = true;
         break;
       case NS_TOUCH_START: {
         WidgetTouchEvent* touchEvent = aEvent->AsTouchEvent();
         // if there is only one touch in this touchstart event, assume that it is
         // the start of a new touch session and evict any old touches in the
         // queue
         if (touchEvent->touches.Length() == 1) {
-          WidgetTouchEvent::TouchArray touches;
+          WidgetTouchEvent::AutoTouchArray touches;
           gCaptureTouchList->Enumerate(&AppendToTouchList, (void *)&touches);
           for (uint32_t i = 0; i < touches.Length(); ++i) {
             EvictTouchPoint(touches[i]);
           }
         }
         // Add any new touches to the queue
         for (uint32_t i = 0; i < touchEvent->touches.Length(); ++i) {
           dom::Touch* touch = touchEvent->touches[i];
--- a/widget/TouchEvents.h
+++ b/widget/TouchEvents.h
@@ -151,16 +151,17 @@ public:
 /******************************************************************************
  * mozilla::WidgetTouchEvent
  ******************************************************************************/
 
 class WidgetTouchEvent : public WidgetInputEvent
 {
 public:
   typedef nsTArray<nsRefPtr<mozilla::dom::Touch>> TouchArray;
+  typedef nsAutoTArray<nsRefPtr<mozilla::dom::Touch>, 10> AutoTouchArray;
 
   virtual WidgetTouchEvent* AsTouchEvent() MOZ_OVERRIDE { return this; }
 
   WidgetTouchEvent()
   {
   }
 
   WidgetTouchEvent(const WidgetTouchEvent& aOther) :