From 6c23424bbb703f6deddbe9bec73ba816a1cfc4f6 Mon Sep 17 00:00:00 2001 From: "zandobersek@gmail.com" Date: Thu, 31 Oct 2013 15:29:28 +0000 Subject: [PATCH] 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): git-svn-id: https://svn.webkit.org/repository/webkit/trunk@158359 268f45cc-cd09-0410-ab3c-d52691b4dbfc --- Source/WebCore/ChangeLog | 29 +++++++++++++++++++++++++ Source/WebCore/svg/SVGAnimatedPath.cpp | 12 +++++----- Source/WebCore/svg/SVGAnimatedType.cpp | 4 ++-- Source/WebCore/svg/SVGAnimatedType.h | 2 +- Source/WebCore/svg/SVGPathByteStream.h | 23 ++++++-------------- Source/WebCore/svg/SVGPathByteStreamBuilder.cpp | 1 - Source/WebCore/svg/SVGPathByteStreamBuilder.h | 1 - Source/WebCore/svg/SVGPathElement.cpp | 2 +- Source/WebCore/svg/SVGPathElement.h | 2 +- Source/WebCore/svg/SVGPathUtilities.cpp | 4 ++-- 10 files changed, 49 insertions(+), 31 deletions(-) diff --git a/Source/WebCore/ChangeLog b/Source/WebCore/ChangeLog index c918ef3..5b7d72c 100644 --- a/Source/WebCore/ChangeLog +++ b/Source/WebCore/ChangeLog @@ -1,3 +1,32 @@ +2013-10-31 Zan Dobersek + + 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 Removing m_maxDeadCapacity condition in fast path in MemoryCache::prune(). diff --git a/Source/WebCore/svg/SVGAnimatedPath.cpp b/Source/WebCore/svg/SVGAnimatedPath.cpp index e595f34..132903b 100644 --- a/Source/WebCore/svg/SVGAnimatedPath.cpp +++ b/Source/WebCore/svg/SVGAnimatedPath.cpp @@ -35,9 +35,9 @@ SVGAnimatedPathAnimator::SVGAnimatedPathAnimator(SVGAnimationElement* animationE PassOwnPtr SVGAnimatedPathAnimator::constructFromString(const String& string) { - OwnPtr byteStream = SVGPathByteStream::create(); + auto byteStream = std::make_unique(); buildSVGPathByteStreamFromString(string, byteStream.get(), UnalteredParsing); - return SVGAnimatedType::createPath(byteStream.release()); + return SVGAnimatedType::createPath(std::move(byteStream)); } PassOwnPtr SVGAnimatedPathAnimator::startAnimValAnimation(const SVGElementAnimatedPropertyList& animatedTypes) @@ -47,7 +47,7 @@ PassOwnPtr SVGAnimatedPathAnimator::startAnimValAnimation(const const SVGPathSegList& baseValue = property->currentBaseValue(); // Build initial path byte stream. - OwnPtr byteStream = SVGPathByteStream::create(); + auto byteStream = std::make_unique(); buildSVGPathByteStreamFromSVGPathSegList(baseValue, byteStream.get(), UnalteredParsing); Vector> result; @@ -62,7 +62,7 @@ PassOwnPtr 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 underlyingPath; + std::unique_ptr 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 lastAnimatedPath; + std::unique_ptr lastAnimatedPath; if (!fromPath->size() || (m_animationElement->isAdditive() && !isToAnimation)) lastAnimatedPath = animatedPath->copy(); diff --git a/Source/WebCore/svg/SVGAnimatedType.cpp b/Source/WebCore/svg/SVGAnimatedType.cpp index b3fd7a0..5a17f1b 100644 --- a/Source/WebCore/svg/SVGAnimatedType.cpp +++ b/Source/WebCore/svg/SVGAnimatedType.cpp @@ -180,11 +180,11 @@ PassOwnPtr SVGAnimatedType::createNumberOptionalNumber(pair SVGAnimatedType::createPath(PassOwnPtr path) +PassOwnPtr SVGAnimatedType::createPath(std::unique_ptr path) { ASSERT(path); OwnPtr animatedType = adoptPtr(new SVGAnimatedType(AnimatedPath)); - animatedType->m_data.path = path.leakPtr(); + animatedType->m_data.path = path.release(); return animatedType.release(); } diff --git a/Source/WebCore/svg/SVGAnimatedType.h b/Source/WebCore/svg/SVGAnimatedType.h index 5376b8f..8ac74a1 100644 --- a/Source/WebCore/svg/SVGAnimatedType.h +++ b/Source/WebCore/svg/SVGAnimatedType.h @@ -52,7 +52,7 @@ public: static PassOwnPtr createNumber(float*); static PassOwnPtr createNumberList(SVGNumberList*); static PassOwnPtr createNumberOptionalNumber(std::pair*); - static PassOwnPtr createPath(PassOwnPtr); + static PassOwnPtr createPath(std::unique_ptr); static PassOwnPtr createPointList(SVGPointList*); static PassOwnPtr createPreserveAspectRatio(SVGPreserveAspectRatio*); static PassOwnPtr createRect(FloatRect*); diff --git a/Source/WebCore/svg/SVGPathByteStream.h b/Source/WebCore/svg/SVGPathByteStream.h index 523faec..715285b 100644 --- a/Source/WebCore/svg/SVGPathByteStream.h +++ b/Source/WebCore/svg/SVGPathByteStream.h @@ -22,7 +22,6 @@ #if ENABLE(SVG) #include -#include #include namespace WebCore { @@ -46,19 +45,17 @@ typedef union { class SVGPathByteStream { WTF_MAKE_FAST_ALLOCATED; public: - static PassOwnPtr create() - { - return adoptPtr(new SVGPathByteStream); - } + typedef Vector Data; + typedef Data::const_iterator DataIterator; - PassOwnPtr copy() + SVGPathByteStream() { } + SVGPathByteStream(const Data& data) : m_data(data) { } + + std::unique_ptr copy() const { - return adoptPtr(new SVGPathByteStream(m_data)); + return std::make_unique(m_data); } - typedef Vector 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; }; diff --git a/Source/WebCore/svg/SVGPathByteStreamBuilder.cpp b/Source/WebCore/svg/SVGPathByteStreamBuilder.cpp index cf939f0..eda2c26 100644 --- a/Source/WebCore/svg/SVGPathByteStreamBuilder.cpp +++ b/Source/WebCore/svg/SVGPathByteStreamBuilder.cpp @@ -25,7 +25,6 @@ #include "SVGPathParser.h" #include "SVGPathSeg.h" #include "SVGPathStringSource.h" -#include namespace WebCore { diff --git a/Source/WebCore/svg/SVGPathByteStreamBuilder.h b/Source/WebCore/svg/SVGPathByteStreamBuilder.h index 37c7906..5b2b471 100644 --- a/Source/WebCore/svg/SVGPathByteStreamBuilder.h +++ b/Source/WebCore/svg/SVGPathByteStreamBuilder.h @@ -24,7 +24,6 @@ #include "FloatPoint.h" #include "SVGPathByteStream.h" #include "SVGPathConsumer.h" -#include #include namespace WebCore { diff --git a/Source/WebCore/svg/SVGPathElement.cpp b/Source/WebCore/svg/SVGPathElement.cpp index b87bc26..fc21bf7 100644 --- a/Source/WebCore/svg/SVGPathElement.cpp +++ b/Source/WebCore/svg/SVGPathElement.cpp @@ -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()) , m_pathSegList(PathSegUnalteredRole) , m_isAnimValObserved(false) { diff --git a/Source/WebCore/svg/SVGPathElement.h b/Source/WebCore/svg/SVGPathElement.h index e9f45972..47eccfb 100644 --- a/Source/WebCore/svg/SVGPathElement.h +++ b/Source/WebCore/svg/SVGPathElement.h @@ -126,7 +126,7 @@ private: void invalidateMPathDependencies(); private: - OwnPtr m_pathByteStream; + std::unique_ptr m_pathByteStream; mutable SVGSynchronizableAnimatedProperty m_pathSegList; bool m_isAnimValObserved; }; diff --git a/Source/WebCore/svg/SVGPathUtilities.cpp b/Source/WebCore/svg/SVGPathUtilities.cpp index 092ba4d..e86e74a 100644 --- a/Source/WebCore/svg/SVGPathUtilities.cpp +++ b/Source/WebCore/svg/SVGPathUtilities.cpp @@ -148,7 +148,7 @@ bool appendSVGPathByteStreamFromSVGPathSeg(PassRefPtr pathSeg, SVGPa SVGPathSegList appendedItemList(PathSegUnalteredRole); appendedItemList.append(pathSeg); - OwnPtr appendedByteStream = SVGPathByteStream::create(); + auto appendedByteStream = std::make_unique(); SVGPathByteStreamBuilder* builder = globalSVGPathByteStreamBuilder(appendedByteStream.get()); OwnPtr source = SVGPathSegListSource::create(appendedItemList); @@ -270,7 +270,7 @@ bool addToSVGPathByteStream(SVGPathByteStream* fromStream, SVGPathByteStream* by SVGPathByteStreamBuilder* builder = globalSVGPathByteStreamBuilder(fromStream); - OwnPtr fromStreamCopy = fromStream->copy(); + auto fromStreamCopy = fromStream->copy(); fromStream->clear(); OwnPtr fromSource = SVGPathByteStreamSource::create(fromStreamCopy.get()); -- 1.8.3.1