aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/core
diff options
context:
space:
mode:
authorGravatar reed@google.com <reed@google.com@2bbb7eff-a529-9590-31e7-b0007b416f81>2012-05-15 13:33:57 +0000
committerGravatar reed@google.com <reed@google.com@2bbb7eff-a529-9590-31e7-b0007b416f81>2012-05-15 13:33:57 +0000
commit2e0d727942c26339425bc5ba26189af070081213 (patch)
treef346c31be358f891d26a853b82f48c83624f87f1 /src/core
parent129ec22cb054592261e001294c430c9dd4e90ff4 (diff)
pre allocate space for the result (guesstimation) so we don't spend extra time
re-growing while we build the stroke. git-svn-id: http://skia.googlecode.com/svn/trunk@3934 2bbb7eff-a529-9590-31e7-b0007b416f81
Diffstat (limited to 'src/core')
-rw-r--r--src/core/SkStroke.cpp21
1 files changed, 17 insertions, 4 deletions
diff --git a/src/core/SkStroke.cpp b/src/core/SkStroke.cpp
index 31c36bafee..1c9b0c04d7 100644
--- a/src/core/SkStroke.cpp
+++ b/src/core/SkStroke.cpp
@@ -63,7 +63,8 @@ static bool set_normal_unitnormal(const SkVector& vec,
class SkPathStroker {
public:
- SkPathStroker(SkScalar radius, SkScalar miterLimit, SkPaint::Cap cap,
+ SkPathStroker(const SkPath& src,
+ SkScalar radius, SkScalar miterLimit, SkPaint::Cap cap,
SkPaint::Join join);
void moveTo(const SkPoint&);
@@ -171,13 +172,16 @@ void SkPathStroker::finishContour(bool close, bool currIsLine) {
fOuter.close();
}
}
- fInner.reset();
+ // since we may re-use fInner, we rewind instead of reset, to save on
+ // reallocating its internal storage.
+ fInner.rewind();
fSegmentCount = -1;
}
///////////////////////////////////////////////////////////////////////////////
-SkPathStroker::SkPathStroker(SkScalar radius, SkScalar miterLimit,
+SkPathStroker::SkPathStroker(const SkPath& src,
+ SkScalar radius, SkScalar miterLimit,
SkPaint::Cap cap, SkPaint::Join join)
: fRadius(radius) {
@@ -197,6 +201,15 @@ SkPathStroker::SkPathStroker(SkScalar radius, SkScalar miterLimit,
fJoiner = SkStrokerPriv::JoinFactory(join);
fSegmentCount = -1;
fPrevIsLine = false;
+
+ // Need some estimate of how large our final result (fOuter)
+ // and our per-contour temp (fInner) will be, so we don't spend
+ // extra time repeatedly growing these arrays.
+ //
+ // 3x for result == inner + outer + join (swag)
+ // 1x for inner == 'wag' (worst contour length would be better guess)
+ fOuter.incReserve(src.countPoints() * 3);
+ fInner.incReserve(src.countPoints());
}
void SkPathStroker::moveTo(const SkPoint& pt) {
@@ -571,7 +584,7 @@ void SkStroke::strokePath(const SkPath& src, SkPath* dst) const {
}
#endif
- SkPathStroker stroker(radius, fMiterLimit, this->getCap(),
+ SkPathStroker stroker(src, radius, fMiterLimit, this->getCap(),
this->getJoin());
SkPath::Iter iter(src, false);