addPoly() entry-point, to quickly add MoveTo+N*LineTo (useful in dashing)
Review URL: https://codereview.appspot.com/6256063

git-svn-id: http://skia.googlecode.com/svn/trunk@4061 2bbb7eff-a529-9590-31e7-b0007b416f81
diff --git a/src/core/SkPath.cpp b/src/core/SkPath.cpp
index ee6a171..5f63651 100644
--- a/src/core/SkPath.cpp
+++ b/src/core/SkPath.cpp
@@ -12,6 +12,11 @@
 #include "SkWriter32.h"
 #include "SkMath.h"
 
+// This value is just made-up for now. When count is 4, calling memset was much
+// slower than just writing the loop. This seems odd, and hopefully in the
+// future this we appear to have been a fluke...
+#define MIN_COUNT_FOR_MEMSET_TO_BE_FAST 16
+
 ////////////////////////////////////////////////////////////////////////////
 
 /**
@@ -627,6 +632,39 @@
     this->close();
 }
 
+void SkPath::addPoly(const SkPoint pts[], int count, bool close) {
+    SkDEBUGCODE(this->validate();)
+    if (count <= 0) {
+        return;
+    }
+
+    fLastMoveToIndex = fPts.count();
+    fPts.append(count, pts);
+
+    // +close makes room for the extra kClose_Verb
+    uint8_t* vb = fVerbs.append(count + close);
+    vb[0] = kMove_Verb;
+
+    if (count > 1) {
+        // cast to unsigned, so if MIN_COUNT_FOR_MEMSET_TO_BE_FAST is defined to
+        // be 0, the compiler will remove the test/branch entirely.
+        if ((unsigned)count >= MIN_COUNT_FOR_MEMSET_TO_BE_FAST) {
+            memset(&vb[1], kLine_Verb, count - 1);
+        } else {
+            for (int i = 1; i < count; ++i) {
+                vb[i] = kLine_Verb;
+            }
+        }
+        fSegmentMask |= kLine_SegmentMask;
+    }
+    if (close) {
+        vb[count] = kClose_Verb;
+    }
+
+    GEN_ID_INC;
+    DIRTY_AFTER_EDIT;
+}
+
 #define CUBIC_ARC_FACTOR    ((SK_ScalarSqrt2 - SK_Scalar1) * 4 / 3)
 
 void SkPath::addRoundRect(const SkRect& rect, SkScalar rx, SkScalar ry,