Bug 815671 part 6. Fixes to widget code to not copy arrays implicitly. r=jlebar
authorBoris Zbarsky <bzbarsky@mit.edu>
Thu, 29 Nov 2012 11:14:14 -0500
changeset 123607 ef768d59bb71ec6d08ba456c609ee5e16a0a8c7a
parent 123606 c2e33f49c60f853246cd9f1b8c5fdfffddf24007
child 123608 414f6acb19860ff6440e3cb314a83c8e39ab5fc7
push id2151
push userlsblakk@mozilla.com
push dateTue, 19 Feb 2013 18:06:57 +0000
treeherdermozilla-beta@4952e88741ec [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjlebar
bugs815671
milestone20.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 815671 part 6. Fixes to widget code to not copy arrays implicitly. r=jlebar
widget/android/AndroidJavaWrappers.h
widget/android/nsAppShell.cpp
widget/android/nsWindow.cpp
widget/windows/nsWindow.cpp
--- a/widget/android/AndroidJavaWrappers.h
+++ b/widget/android/AndroidJavaWrappers.h
@@ -650,21 +650,21 @@ public:
     void Init(int aType);
     void Init(int x1, int y1, int x2, int y2);
     void Init(int aType, const nsIntRect &aRect);
     void Init(AndroidGeckoEvent *aResizeEvent);
 
     int Action() { return mAction; }
     int Type() { return mType; }
     int64_t Time() { return mTime; }
-    nsTArray<nsIntPoint> Points() { return mPoints; }
-    nsTArray<int> PointIndicies() { return mPointIndicies; }
-    nsTArray<float> Pressures() { return mPressures; }
-    nsTArray<float> Orientations() { return mOrientations; }
-    nsTArray<nsIntPoint> PointRadii() { return mPointRadii; }
+    const nsTArray<nsIntPoint>& Points() { return mPoints; }
+    const nsTArray<int>& PointIndicies() { return mPointIndicies; }
+    const nsTArray<float>& Pressures() { return mPressures; }
+    const nsTArray<float>& Orientations() { return mOrientations; }
+    const nsTArray<nsIntPoint>& PointRadii() { return mPointRadii; }
     double X() { return mX; }
     double Y() { return mY; }
     double Z() { return mZ; }
     const nsIntRect& Rect() { return mRect; }
     nsAString& Characters() { return mCharacters; }
     nsAString& CharactersExtra() { return mCharactersExtra; }
     int KeyCode() { return mKeyCode; }
     int MetaState() { return mMetaState; }
--- a/widget/android/nsAppShell.cpp
+++ b/widget/android/nsAppShell.cpp
@@ -66,17 +66,19 @@ nsIGeolocationUpdate *gLocationCallback 
 nsAutoPtr<mozilla::AndroidGeckoEvent> gLastSizeChange;
 
 nsAppShell *nsAppShell::gAppShell = nullptr;
 
 NS_IMPL_ISUPPORTS_INHERITED1(nsAppShell, nsBaseAppShell, nsIObserver)
 
 class ScreenshotRunnable : public nsRunnable {
 public:
-    ScreenshotRunnable(nsIAndroidBrowserApp* aBrowserApp, int aTabId, nsTArray<nsIntPoint>& aPoints, int aToken, RefCountedJavaObject* aBuffer):
+    ScreenshotRunnable(nsIAndroidBrowserApp* aBrowserApp, int aTabId,
+                       const nsTArray<nsIntPoint>& aPoints, int aToken,
+                       RefCountedJavaObject* aBuffer):
         mBrowserApp(aBrowserApp), mPoints(aPoints), mTabId(aTabId), mToken(aToken), mBuffer(aBuffer) {}
 
     virtual nsresult Run() {
         nsCOMPtr<nsIDOMWindow> domWindow;
         nsCOMPtr<nsIBrowserTab> tab;
         mBrowserApp->GetBrowserTab(mTabId, getter_AddRefs(tab));
         if (!tab)
             return NS_OK;
@@ -501,17 +503,17 @@ nsAppShell::ProcessNextNativeEvent(bool 
             break;
 
         AndroidBridge* bridge = AndroidBridge::Bridge();
         if (!bridge)
             break;
 
         int32_t token = curEvent->Flags();
         int32_t tabId = curEvent->MetaState();
-        nsTArray<nsIntPoint> points = curEvent->Points();
+        const nsTArray<nsIntPoint>& points = curEvent->Points();
         RefCountedJavaObject* buffer = curEvent->ByteBuffer();
         nsCOMPtr<ScreenshotRunnable> sr = 
             new ScreenshotRunnable(mBrowserApp, tabId, points, token, buffer);
         MessageLoop::current()->PostIdleTask(
             FROM_HERE, NewRunnableMethod(sr.get(), &ScreenshotRunnable::Run));
         break;
     }
 
--- a/widget/android/nsWindow.cpp
+++ b/widget/android/nsWindow.cpp
@@ -752,17 +752,17 @@ nsWindow::OnGlobalAndroidEvent(AndroidGe
             win->mBounds.width = 0;
             win->mBounds.height = 0;
             // also resize the children
             for (uint32_t i = 0; i < win->mChildren.Length(); i++) {
                 win->mChildren[i]->mBounds.width = 0;
                 win->mChildren[i]->mBounds.height = 0;
             }
         case AndroidGeckoEvent::SIZE_CHANGED: {
-            nsTArray<nsIntPoint> points = ae->Points();
+            const nsTArray<nsIntPoint>& points = ae->Points();
             NS_ASSERTION(points.Length() == 2, "Size changed does not have enough coordinates");
 
             int nw = points[0].x;
             int nh = points[0].y;
 
             if (ae->Type() == AndroidGeckoEvent::FORCED_RESIZE || nw != gAndroidBounds.width ||
                 nh != gAndroidBounds.height) {
 
@@ -822,17 +822,17 @@ nsWindow::OnGlobalAndroidEvent(AndroidGe
             }
             break;
         }
 
         case AndroidGeckoEvent::MOTION_EVENT: {
             win->UserActivity();
             if (!gTopLevelWindows.IsEmpty()) {
                 nsIntPoint pt(0,0);
-                nsTArray<nsIntPoint> points = ae->Points();
+                const nsTArray<nsIntPoint>& points = ae->Points();
                 if (points.Length() > 0) {
                     pt = points[0];
                 }
                 pt.x = clamped(pt.x, 0, NS_MAX(gAndroidBounds.width - 1, 0));
                 pt.y = clamped(pt.y, 0, NS_MAX(gAndroidBounds.height - 1, 0));
                 nsWindow *target = win->FindWindowForPoint(pt);
 #if 0
                 ALOG("MOTION_EVENT %f,%f -> %p (visible: %d children: %d)", pt.x, pt.y, (void*)target,
@@ -847,17 +847,17 @@ nsWindow::OnGlobalAndroidEvent(AndroidGe
                         target->OnMouseEvent(ae);
                 }
             }
             break;
         }
 
         case AndroidGeckoEvent::NATIVE_GESTURE_EVENT: {
             nsIntPoint pt(0,0);
-            nsTArray<nsIntPoint> points = ae->Points();
+            const nsTArray<nsIntPoint>& points = ae->Points();
             if (points.Length() > 0) {
                 pt = points[0];
             }
             pt.x = clamped(pt.x, 0, NS_MAX(gAndroidBounds.width - 1, 0));
             pt.y = clamped(pt.y, 0, NS_MAX(gAndroidBounds.height - 1, 0));
             nsWindow *target = win->FindWindowForPoint(pt);
 
             target->OnNativeGestureEvent(ae);
--- a/widget/windows/nsWindow.cpp
+++ b/widget/windows/nsWindow.cpp
@@ -6977,25 +6977,23 @@ CreateHRGNFromArray(const nsTArray<nsInt
     const nsIntRect& r = aRects[i];
     bounds.UnionRect(bounds, r);
     ::SetRect(&rects[i], r.x, r.y, r.XMost(), r.YMost());
   }
   ::SetRect(&data->rdh.rcBound, bounds.x, bounds.y, bounds.XMost(), bounds.YMost());
   return ::ExtCreateRegion(NULL, buf.Length(), data);
 }
 
-static const nsTArray<nsIntRect>
-ArrayFromRegion(const nsIntRegion& aRegion)
-{
-  nsTArray<nsIntRect> rects;
+static void
+ArrayFromRegion(const nsIntRegion& aRegion, nsTArray<nsIntRect>& aRects)
+{
   const nsIntRect* r;
   for (nsIntRegionRectIterator iter(aRegion); (r = iter.Next());) {
-    rects.AppendElement(*r);
-  }
-  return rects;
+    aRects.AppendElement(*r);
+  }
 }
 
 nsresult
 nsWindow::SetWindowClipRegion(const nsTArray<nsIntRect>& aRects,
                               bool aIntersectWithExisting)
 {
   if (!aIntersectWithExisting) {
     if (!StoreWindowClipRegion(aRects))
@@ -7015,17 +7013,18 @@ nsWindow::SetWindowClipRegion(const nsTA
     // create region from them
     nsIntRegion currentRegion = RegionFromArray(currentRects);
     // create region from new rects
     nsIntRegion newRegion = RegionFromArray(aRects);
     // intersect regions
     nsIntRegion intersection;
     intersection.And(currentRegion, newRegion);
     // create int rect array from intersection
-    nsTArray<nsIntRect> rects = ArrayFromRegion(intersection);
+    nsTArray<nsIntRect> rects;
+    ArrayFromRegion(intersection, rects);
     // store
     if (!StoreWindowClipRegion(rects))
       return NS_OK;
   }
 
   HRGN dest = CreateHRGNFromArray(aRects);
   if (!dest)
     return NS_ERROR_OUT_OF_MEMORY;