Manage SVGPathByteStream through std::unique_ptr
authorzandobersek@gmail.com <zandobersek@gmail.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 31 Oct 2013 15:29:28 +0000 (15:29 +0000)
committerzandobersek@gmail.com <zandobersek@gmail.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 31 Oct 2013 15:29:28 +0000 (15:29 +0000)
https://bugs.webkit.org/show_bug.cgi?id=123467

Reviewed by Anders Carlsson.

Manage SVGPathByteStream objects through std::unique_ptr. Constructors for the class are made public
so std::make_unique can be used with the class.

* svg/SVGAnimatedPath.cpp:
(WebCore::SVGAnimatedPathAnimator::constructFromString):
(WebCore::SVGAnimatedPathAnimator::startAnimValAnimation):
(WebCore::SVGAnimatedPathAnimator::calculateAnimatedValue):
* svg/SVGAnimatedType.cpp:
(WebCore::SVGAnimatedType::createPath):
* svg/SVGAnimatedType.h:
* svg/SVGPathByteStream.h:
(WebCore::SVGPathByteStream::SVGPathByteStream): Takes a const Data object that's then copied.
(WebCore::SVGPathByteStream::copy): Made const.
* svg/SVGPathByteStreamBuilder.cpp: Remove an unnecessary include.
* svg/SVGPathByteStreamBuilder.h: Ditto.
* svg/SVGPathElement.cpp:
(WebCore::SVGPathElement::SVGPathElement):
* svg/SVGPathElement.h:
* svg/SVGPathUtilities.cpp:
(WebCore::appendSVGPathByteStreamFromSVGPathSeg):
(WebCore::addToSVGPathByteStream):

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@158359 268f45cc-cd09-0410-ab3c-d52691b4dbfc

Source/WebCore/ChangeLog
Source/WebCore/svg/SVGAnimatedPath.cpp
Source/WebCore/svg/SVGAnimatedType.cpp
Source/WebCore/svg/SVGAnimatedType.h
Source/WebCore/svg/SVGPathByteStream.h
Source/WebCore/svg/SVGPathByteStreamBuilder.cpp
Source/WebCore/svg/SVGPathByteStreamBuilder.h
Source/WebCore/svg/SVGPathElement.cpp
Source/WebCore/svg/SVGPathElement.h
Source/WebCore/svg/SVGPathUtilities.cpp

index c918ef3..5b7d72c 100644 (file)
@@ -1,3 +1,32 @@
+2013-10-31  Zan Dobersek  <zdobersek@igalia.com>
+
+        Manage SVGPathByteStream through std::unique_ptr
+        https://bugs.webkit.org/show_bug.cgi?id=123467
+
+        Reviewed by Anders Carlsson.
+
+        Manage SVGPathByteStream objects through std::unique_ptr. Constructors for the class are made public
+        so std::make_unique can be used with the class.
+
+        * svg/SVGAnimatedPath.cpp:
+        (WebCore::SVGAnimatedPathAnimator::constructFromString):
+        (WebCore::SVGAnimatedPathAnimator::startAnimValAnimation):
+        (WebCore::SVGAnimatedPathAnimator::calculateAnimatedValue):
+        * svg/SVGAnimatedType.cpp:
+        (WebCore::SVGAnimatedType::createPath):
+        * svg/SVGAnimatedType.h:
+        * svg/SVGPathByteStream.h:
+        (WebCore::SVGPathByteStream::SVGPathByteStream): Takes a const Data object that's then copied.
+        (WebCore::SVGPathByteStream::copy): Made const.
+        * svg/SVGPathByteStreamBuilder.cpp: Remove an unnecessary include.
+        * svg/SVGPathByteStreamBuilder.h: Ditto.
+        * svg/SVGPathElement.cpp:
+        (WebCore::SVGPathElement::SVGPathElement):
+        * svg/SVGPathElement.h:
+        * svg/SVGPathUtilities.cpp:
+        (WebCore::appendSVGPathByteStreamFromSVGPathSeg):
+        (WebCore::addToSVGPathByteStream):
+
 2013-10-31  Marcin Bychawski  <m.bychawski@samsung.com>
 
         Removing m_maxDeadCapacity condition in fast path in MemoryCache::prune().
index e595f34..132903b 100644 (file)
@@ -35,9 +35,9 @@ SVGAnimatedPathAnimator::SVGAnimatedPathAnimator(SVGAnimationElement* animationE
 
 PassOwnPtr<SVGAnimatedType> SVGAnimatedPathAnimator::constructFromString(const String& string)
 {
-    OwnPtr<SVGPathByteStream> byteStream = SVGPathByteStream::create();
+    auto byteStream = std::make_unique<SVGPathByteStream>();
     buildSVGPathByteStreamFromString(string, byteStream.get(), UnalteredParsing);
-    return SVGAnimatedType::createPath(byteStream.release());
+    return SVGAnimatedType::createPath(std::move(byteStream));
 }
 
 PassOwnPtr<SVGAnimatedType> SVGAnimatedPathAnimator::startAnimValAnimation(const SVGElementAnimatedPropertyList& animatedTypes)
@@ -47,7 +47,7 @@ PassOwnPtr<SVGAnimatedType> SVGAnimatedPathAnimator::startAnimValAnimation(const
     const SVGPathSegList& baseValue = property->currentBaseValue();
 
     // Build initial path byte stream.
-    OwnPtr<SVGPathByteStream> byteStream = SVGPathByteStream::create();
+    auto byteStream = std::make_unique<SVGPathByteStream>();
     buildSVGPathByteStreamFromSVGPathSegList(baseValue, byteStream.get(), UnalteredParsing);
 
     Vector<RefPtr<SVGAnimatedPathSegListPropertyTearOff>> result;
@@ -62,7 +62,7 @@ PassOwnPtr<SVGAnimatedType> SVGAnimatedPathAnimator::startAnimValAnimation(const
     for (size_t i = 0; i < resultSize; ++i)
         result[i]->animationStarted(byteStream.get(), &baseValue);
 
-    return SVGAnimatedType::createPath(byteStream.release());
+    return SVGAnimatedType::createPath(std::move(byteStream));
 }
 
 void SVGAnimatedPathAnimator::stopAnimValAnimation(const SVGElementAnimatedPropertyList& animatedTypes)
@@ -112,7 +112,7 @@ void SVGAnimatedPathAnimator::calculateAnimatedValue(float percentage, unsigned
     SVGPathByteStream* toAtEndOfDurationPath = toAtEndOfDuration->path();
     SVGPathByteStream* animatedPath = animated->path();
 
-    OwnPtr<SVGPathByteStream> underlyingPath;
+    std::unique_ptr<SVGPathByteStream> underlyingPath;
     bool isToAnimation = m_animationElement->animationMode() == ToAnimation;
     if (isToAnimation) {
         underlyingPath = animatedPath->copy();
@@ -120,7 +120,7 @@ void SVGAnimatedPathAnimator::calculateAnimatedValue(float percentage, unsigned
     }
 
     // Cache the current animated value before the buildAnimatedSVGPathByteStream() clears animatedPath.
-    OwnPtr<SVGPathByteStream> lastAnimatedPath;
+    std::unique_ptr<SVGPathByteStream> lastAnimatedPath;
     if (!fromPath->size() || (m_animationElement->isAdditive() && !isToAnimation))
         lastAnimatedPath = animatedPath->copy();
 
index b3fd7a0..5a17f1b 100644 (file)
@@ -180,11 +180,11 @@ PassOwnPtr<SVGAnimatedType> SVGAnimatedType::createNumberOptionalNumber(pair<flo
     return animatedType.release();
 }
 
-PassOwnPtr<SVGAnimatedType> SVGAnimatedType::createPath(PassOwnPtr<SVGPathByteStream> path)
+PassOwnPtr<SVGAnimatedType> SVGAnimatedType::createPath(std::unique_ptr<SVGPathByteStream> path)
 {
     ASSERT(path);
     OwnPtr<SVGAnimatedType> animatedType = adoptPtr(new SVGAnimatedType(AnimatedPath));
-    animatedType->m_data.path = path.leakPtr();
+    animatedType->m_data.path = path.release();
     return animatedType.release();
 }
 
index 5376b8f..8ac74a1 100644 (file)
@@ -52,7 +52,7 @@ public:
     static PassOwnPtr<SVGAnimatedType> createNumber(float*);
     static PassOwnPtr<SVGAnimatedType> createNumberList(SVGNumberList*);
     static PassOwnPtr<SVGAnimatedType> createNumberOptionalNumber(std::pair<float, float>*);
-    static PassOwnPtr<SVGAnimatedType> createPath(PassOwnPtr<SVGPathByteStream>);
+    static PassOwnPtr<SVGAnimatedType> createPath(std::unique_ptr<SVGPathByteStream>);
     static PassOwnPtr<SVGAnimatedType> createPointList(SVGPointList*);
     static PassOwnPtr<SVGAnimatedType> createPreserveAspectRatio(SVGPreserveAspectRatio*);
     static PassOwnPtr<SVGAnimatedType> createRect(FloatRect*);
index 523faec..715285b 100644 (file)
@@ -22,7 +22,6 @@
 
 #if ENABLE(SVG)
 #include <wtf/Noncopyable.h>
-#include <wtf/PassOwnPtr.h>
 #include <wtf/Vector.h>
 
 namespace WebCore {
@@ -46,19 +45,17 @@ typedef union {
 class SVGPathByteStream {
     WTF_MAKE_FAST_ALLOCATED;
 public:
-    static PassOwnPtr<SVGPathByteStream> create()
-    {
-        return adoptPtr(new SVGPathByteStream);
-    }
+    typedef Vector<unsigned char> Data;
+    typedef Data::const_iterator DataIterator;
 
-    PassOwnPtr<SVGPathByteStream> copy()
+    SVGPathByteStream() { }
+    SVGPathByteStream(const Data& data) : m_data(data) { }
+
+    std::unique_ptr<SVGPathByteStream> copy() const
     {
-        return adoptPtr(new SVGPathByteStream(m_data));
+        return std::make_unique<SVGPathByteStream>(m_data);
     }
 
-    typedef Vector<unsigned char> Data;
-    typedef Data::const_iterator DataIterator;
-
     DataIterator begin() { return m_data.begin(); }
     DataIterator end() { return m_data.end(); }
     void append(unsigned char byte) { m_data.append(byte); }
@@ -75,12 +72,6 @@ public:
     void resize(unsigned) { }
 
 private:
-    SVGPathByteStream() { }
-    SVGPathByteStream(Data& data)
-        : m_data(data)
-    {
-    }
-
     Data m_data;
 };
 
index cf939f0..eda2c26 100644 (file)
@@ -25,7 +25,6 @@
 #include "SVGPathParser.h"
 #include "SVGPathSeg.h"
 #include "SVGPathStringSource.h"
-#include <wtf/OwnPtr.h>
 
 namespace WebCore {
 
index 37c7906..5b2b471 100644 (file)
@@ -24,7 +24,6 @@
 #include "FloatPoint.h"
 #include "SVGPathByteStream.h"
 #include "SVGPathConsumer.h"
-#include <wtf/PassOwnPtr.h>
 #include <wtf/text/WTFString.h>
 
 namespace WebCore {
index b87bc26..fc21bf7 100644 (file)
@@ -84,7 +84,7 @@ END_REGISTER_ANIMATED_PROPERTIES
 
 inline SVGPathElement::SVGPathElement(const QualifiedName& tagName, Document& document)
     : SVGGraphicsElement(tagName, document)
-    , m_pathByteStream(SVGPathByteStream::create())
+    , m_pathByteStream(std::make_unique<SVGPathByteStream>())
     , m_pathSegList(PathSegUnalteredRole)
     , m_isAnimValObserved(false)
 {
index e9f4597..47eccfb 100644 (file)
@@ -126,7 +126,7 @@ private:
     void invalidateMPathDependencies();
 
 private:
-    OwnPtr<SVGPathByteStream> m_pathByteStream;
+    std::unique_ptr<SVGPathByteStream> m_pathByteStream;
     mutable SVGSynchronizableAnimatedProperty<SVGPathSegList> m_pathSegList;
     bool m_isAnimValObserved;
 };
index 092ba4d..e86e74a 100644 (file)
@@ -148,7 +148,7 @@ bool appendSVGPathByteStreamFromSVGPathSeg(PassRefPtr<SVGPathSeg> pathSeg, SVGPa
 
     SVGPathSegList appendedItemList(PathSegUnalteredRole);
     appendedItemList.append(pathSeg);
-    OwnPtr<SVGPathByteStream> appendedByteStream = SVGPathByteStream::create();
+    auto appendedByteStream = std::make_unique<SVGPathByteStream>();
 
     SVGPathByteStreamBuilder* builder = globalSVGPathByteStreamBuilder(appendedByteStream.get());
     OwnPtr<SVGPathSegListSource> source = SVGPathSegListSource::create(appendedItemList);
@@ -270,7 +270,7 @@ bool addToSVGPathByteStream(SVGPathByteStream* fromStream, SVGPathByteStream* by
 
     SVGPathByteStreamBuilder* builder = globalSVGPathByteStreamBuilder(fromStream);
 
-    OwnPtr<SVGPathByteStream> fromStreamCopy = fromStream->copy();
+    auto fromStreamCopy = fromStream->copy();
     fromStream->clear();
 
     OwnPtr<SVGPathByteStreamSource> fromSource = SVGPathByteStreamSource::create(fromStreamCopy.get());