SkPath: special case adding path to empty path

Chrome has code like:

SkPath path1 = ...;
SkPath path2;

path2.AddPath(path1);

This patch makes AddPath() to an empty path share the same
underlying SkPathRef. Doing this cuts down on unnecessary
allocations.

Change-Id: I806ad59b39eeafdeb5acbf265131ac3bcfb762b0
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/806316
Reviewed-by: Brian Osman <brianosman@google.com>
Reviewed-by: Herb Derby <herb@google.com>
Commit-Queue: Scott Violet <sky@chromium.org>
diff --git a/src/core/SkPath.cpp b/src/core/SkPath.cpp
index 21726d3..3386f97 100644
--- a/src/core/SkPath.cpp
+++ b/src/core/SkPath.cpp
@@ -258,6 +258,7 @@
     }
     out->reset();
     out->addPath(*this);
+    SkPathRef::Editor editor(&(out->fPathRef));
     fPathRef->interpolate(*ending.fPathRef, weight, out->fPathRef.get());
     return true;
 }
@@ -1434,6 +1435,13 @@
         return *this;
     }
 
+    if (this->isEmpty() && matrix.isIdentity()) {
+        const uint8_t fillType = fFillType;
+        *this = srcPath;
+        fFillType = fillType;
+        return *this;
+    }
+
     // Detect if we're trying to add ourself
     const SkPath* src = &srcPath;
     SkTLazy<SkPath> tmp;