Bug 1415961 - construct {Blur,Gradient}CacheData more efficiently; r=jrmuizel
authorNathan Froyd <froydnj@mozilla.com>
Fri, 10 Nov 2017 16:43:54 -0500
changeset 444649 8e62f2933a3995e2503bf15346f3af3a3e50f914
parent 444648 abc17e0eea7749de3c486daf4cb978448e29e449
child 444650 20d4af5881a14ca34bec7fb869b7f161419bc856
push id1618
push userCallek@gmail.com
push dateThu, 11 Jan 2018 17:45:48 +0000
treeherdermozilla-release@882ca853e05a [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjrmuizel
bugs1415961
milestone58.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 1415961 - construct {Blur,Gradient}CacheData more efficiently; r=jrmuizel We pass in `const {Blur,Gradient}CacheKey&` to these functions. There's no need to copy the cache keys here; we can just Move() the existing objects in instead. Doing this saves unnecessary allocations and/or refcounting.
gfx/thebes/gfxBlur.cpp
gfx/thebes/gfxGradientCache.cpp
--- a/gfx/thebes/gfxBlur.cpp
+++ b/gfx/thebes/gfxBlur.cpp
@@ -280,16 +280,18 @@ struct BlurCacheKey : public PLDHashEntr
     , mBlurRadius(aBlurRadius)
     , mShadowColor(aShadowColor)
     , mBackend(aBackendType)
     , mCornerRadii(aCornerRadii ? *aCornerRadii : RectCornerRadii())
     , mIsInset(aIsInset)
     , mInnerMinSize(aInnerMinSize)
   { }
 
+  BlurCacheKey(BlurCacheKey&&) = default;
+
   static PLDHashNumber
   HashKey(const KeyTypePointer aKey)
   {
     PLDHashNumber hash = 0;
     hash = AddToHash(hash, aKey->mMinSize.width, aKey->mMinSize.height);
     hash = AddToHash(hash, aKey->mBlurRadius.width, aKey->mBlurRadius.height);
 
     hash = AddToHash(hash, HashBytes(&aKey->mShadowColor.r,
@@ -339,27 +341,23 @@ struct BlurCacheKey : public PLDHashEntr
   }
 };
 
 /**
  * This class is what is cached. It need to be allocated in an object separated
  * to the cache entry to be able to be tracked by the nsExpirationTracker.
  * */
 struct BlurCacheData {
-  BlurCacheData(SourceSurface* aBlur, const IntMargin& aBlurMargin, const BlurCacheKey& aKey)
+  BlurCacheData(SourceSurface* aBlur, const IntMargin& aBlurMargin, BlurCacheKey&& aKey)
     : mBlur(aBlur)
     , mBlurMargin(aBlurMargin)
-    , mKey(aKey)
+    , mKey(Move(aKey))
   {}
 
-  BlurCacheData(const BlurCacheData& aOther)
-    : mBlur(aOther.mBlur)
-    , mBlurMargin(aOther.mBlurMargin)
-    , mKey(aOther.mKey)
-  { }
+  BlurCacheData(BlurCacheData&& aOther) = default;
 
   nsExpirationState *GetExpirationState() {
     return &mExpirationState;
   }
 
   nsExpirationState mExpirationState;
   RefPtr<SourceSurface> mBlur;
   IntMargin mBlurMargin;
@@ -501,17 +499,17 @@ CacheBlur(DrawTarget* aDT,
           const IntSize& aMinSize,
           const IntSize& aBlurRadius,
           const RectCornerRadii* aCornerRadii,
           const Color& aShadowColor,
           const IntMargin& aBlurMargin,
           SourceSurface* aBoxShadow)
 {
   BlurCacheKey key(aMinSize, aBlurRadius, aCornerRadii, aShadowColor, aDT->GetBackendType());
-  BlurCacheData* data = new BlurCacheData(aBoxShadow, aBlurMargin, key);
+  BlurCacheData* data = new BlurCacheData(aBoxShadow, aBlurMargin, Move(key));
   if (!gBlurCache->RegisterEntry(data)) {
     delete data;
   }
 }
 
 // Blurs a small surface and creates the colored box shadow.
 static already_AddRefed<SourceSurface>
 CreateBoxShadow(DrawTarget* aDestDrawTarget,
@@ -1083,17 +1081,17 @@ CacheInsetBlur(const IntSize& aMinOuterS
                SourceSurface* aBoxShadow)
 {
   bool isInsetBlur = true;
   BlurCacheKey key(aMinOuterSize, aMinInnerSize,
                    aBlurRadius, aCornerRadii,
                    aShadowColor, isInsetBlur,
                    aBackendType);
   IntMargin blurMargin(0, 0, 0, 0);
-  BlurCacheData* data = new BlurCacheData(aBoxShadow, blurMargin, key);
+  BlurCacheData* data = new BlurCacheData(aBoxShadow, blurMargin, Move(key));
   if (!gBlurCache->RegisterEntry(data)) {
     delete data;
   }
 }
 
 already_AddRefed<SourceSurface>
 gfxAlphaBoxBlur::GetInsetBlur(const Rect& aOuterRect,
                               const Rect& aWhitespaceRect,
--- a/gfx/thebes/gfxGradientCache.cpp
+++ b/gfx/thebes/gfxGradientCache.cpp
@@ -29,16 +29,18 @@ struct GradientCacheKey : public PLDHash
   GradientCacheKey(const nsTArray<GradientStop>& aStops, ExtendMode aExtend, BackendType aBackendType)
     : mStops(aStops), mExtend(aExtend), mBackendType(aBackendType)
   { }
 
   explicit GradientCacheKey(const GradientCacheKey* aOther)
     : mStops(aOther->mStops), mExtend(aOther->mExtend), mBackendType(aOther->mBackendType)
   { }
 
+  GradientCacheKey(GradientCacheKey&& aOther) = default;
+
   union FloatUint32
   {
     float    f;
     uint32_t u;
   };
 
   static PLDHashNumber
   HashKey(const KeyTypePointer aKey)
@@ -81,25 +83,22 @@ struct GradientCacheKey : public PLDHash
   }
 };
 
 /**
  * This class is what is cached. It need to be allocated in an object separated
  * to the cache entry to be able to be tracked by the nsExpirationTracker.
  * */
 struct GradientCacheData {
-  GradientCacheData(GradientStops* aStops, const GradientCacheKey& aKey)
+  GradientCacheData(GradientStops* aStops, GradientCacheKey&& aKey)
     : mStops(aStops),
-      mKey(aKey)
+      mKey(Move(aKey))
   {}
 
-  GradientCacheData(const GradientCacheData& aOther)
-    : mStops(aOther.mStops),
-      mKey(aOther.mKey)
-  { }
+  GradientCacheData(GradientCacheData&& aOther) = default;
 
   nsExpirationState *GetExpirationState() {
     return &mExpirationState;
   }
 
   nsExpirationState mExpirationState;
   const RefPtr<GradientStops> mStops;
   GradientCacheKey mKey;