Add ShouldSkip variant that can read a --match flag directly.

Just seemed like we were going through lots of hoops for this common case.

BUG=
R=scroggo@google.com

Author: mtklein@google.com

Review URL: https://chromiumcodereview.appspot.com/23708009

git-svn-id: http://skia.googlecode.com/svn/trunk@11034 2bbb7eff-a529-9590-31e7-b0007b416f81
diff --git a/experimental/SkiaExamples/SkExample.cpp b/experimental/SkiaExamples/SkExample.cpp
index d3601e1..d4adaf4 100644
--- a/experimental/SkiaExamples/SkExample.cpp
+++ b/experimental/SkiaExamples/SkExample.cpp
@@ -42,9 +42,6 @@
     fCurrExample = fRegistry->factory()(this);
 
     if (FLAGS_match.count()) {
-        for(int i = 0; i < FLAGS_match.count(); ++i) {
-            fMatchStrs.push(FLAGS_match[i]);
-        }
         // Start with the a matching sample if possible.
         bool found = this->findNextMatch();
         if (!found) {
@@ -170,7 +167,7 @@
             fRegistry = SkExample::Registry::Head();
         }
         SkExample* next = fRegistry->factory()(this);
-        if (!SkCommandLineFlags::ShouldSkip(fMatchStrs, next->getName().c_str())) {
+        if (!SkCommandLineFlags::ShouldSkip(FLAGS_match, next->getName().c_str())) {
             fCurrExample = next;
             found = true;
         }
diff --git a/experimental/SkiaExamples/SkExample.h b/experimental/SkiaExamples/SkExample.h
index 8efd309..51fe21c 100644
--- a/experimental/SkiaExamples/SkExample.h
+++ b/experimental/SkiaExamples/SkExample.h
@@ -69,7 +69,6 @@
 
     SkExample* fCurrExample;
     const SkExample::Registry* fRegistry;
-    SkTDArray<const char*> fMatchStrs;
     GrContext* fContext;
     GrRenderTarget* fRenderTarget;
     AttachmentInfo fAttachmentInfo;
diff --git a/gm/gmmain.cpp b/gm/gmmain.cpp
index 6fd96f9..c24d9c7 100644
--- a/gm/gmmain.cpp
+++ b/gm/gmmain.cpp
@@ -2093,13 +2093,6 @@
     return true;
 }
 
-static bool parse_flags_match_strs(SkTDArray<const char*>* matchStrs) {
-    for (int i = 0; i < FLAGS_match.count(); ++i) {
-        matchStrs->push(FLAGS_match[i]);
-    }
-    return true;
-}
-
 static bool parse_flags_resource_path() {
     if (FLAGS_resourcePath.count() == 1) {
         GM::SetResourcePath(FLAGS_resourcePath[0]);
@@ -2145,7 +2138,6 @@
 #else
     GrContextFactory* grFactory = NULL;
 #endif
-    SkTDArray<const char*> matchStrs;
 
     if (!parse_flags_modulo(&moduloRemainder, &moduloDivisor) ||
         !parse_flags_ignore_error_types(&gmmain.fIgnorableErrorTypes) ||
@@ -2154,7 +2146,6 @@
 #endif
         !parse_flags_tile_grid_replay_scales(&tileGridReplayScales) ||
         !parse_flags_resource_path() ||
-        !parse_flags_match_strs(&matchStrs) ||
         !parse_flags_jpeg_quality() ||
         !parse_flags_configs(&configs, grFactory) ||
         !parse_flags_pdf_rasterizers(configs, &pdfRasterizers) ||
@@ -2219,7 +2210,7 @@
 
         const char* shortName = gm->shortName();
 
-        if (SkCommandLineFlags::ShouldSkip(matchStrs, shortName)) {
+        if (SkCommandLineFlags::ShouldSkip(FLAGS_match, shortName)) {
             continue;
         }
 
diff --git a/tests/skia_test.cpp b/tests/skia_test.cpp
index a2f5e9c..7d22ff6 100644
--- a/tests/skia_test.cpp
+++ b/tests/skia_test.cpp
@@ -208,15 +208,10 @@
     int toRun = 0;
     Test* test;
 
-    SkTDArray<const char*> matchStrs;
-    for(int i = 0; i < FLAGS_match.count(); ++i) {
-        matchStrs.push(FLAGS_match[i]);
-    }
-
     while ((test = iter.next()) != NULL) {
         SkAutoTDelete<Test> owned(test);
 
-        if(!SkCommandLineFlags::ShouldSkip(matchStrs, test->getName())) {
+        if(!SkCommandLineFlags::ShouldSkip(FLAGS_match, test->getName())) {
             toRun++;
         }
         total++;
@@ -232,7 +227,7 @@
     SkTArray<Test*> unsafeTests;  // Always passes ownership to an SkTestRunnable
     for (int i = 0; i < total; i++) {
         SkAutoTDelete<Test> test(iter.next());
-        if (SkCommandLineFlags::ShouldSkip(matchStrs, test->getName())) {
+        if (SkCommandLineFlags::ShouldSkip(FLAGS_match, test->getName())) {
             ++skipCount;
         } else if (!test->isThreadsafe()) {
             unsafeTests.push_back() = test.detach();
diff --git a/tools/flags/SkCommandLineFlags.cpp b/tools/flags/SkCommandLineFlags.cpp
index 084f48a..656a00a 100644
--- a/tools/flags/SkCommandLineFlags.cpp
+++ b/tools/flags/SkCommandLineFlags.cpp
@@ -304,7 +304,10 @@
     }
 }
 
-bool SkCommandLineFlags::ShouldSkip(const SkTDArray<const char*>& strings, const char* name) {
+namespace {
+
+template <typename Strings>
+bool ShouldSkipImpl(const Strings& strings, const char* name) {
     int count = strings.count();
     size_t testLen = strlen(name);
     bool anyExclude = count == 0;
@@ -334,3 +337,12 @@
     }
     return !anyExclude;
 }
+
+}  // namespace
+
+bool SkCommandLineFlags::ShouldSkip(const SkTDArray<const char*>& strings, const char* name) {
+    return ShouldSkipImpl(strings, name);
+}
+bool SkCommandLineFlags::ShouldSkip(const StringArray& strings, const char* name) {
+    return ShouldSkipImpl(strings, name);
+}
diff --git a/tools/flags/SkCommandLineFlags.h b/tools/flags/SkCommandLineFlags.h
index b0199f6..c324a1f 100644
--- a/tools/flags/SkCommandLineFlags.h
+++ b/tools/flags/SkCommandLineFlags.h
@@ -108,15 +108,6 @@
      */
     static void Parse(int argc, char** argv);
 
-    /* Takes a list of the form [~][^]match[$]
-     ~ causes a matching test to always be skipped
-     ^ requires the start of the test to match
-     $ requires the end of the test to match
-     ^ and $ requires an exact match
-     If a test does not match any list entry, it is skipped unless some list entry starts with ~
-    */
-    static bool ShouldSkip(const SkTDArray<const char*>& strings, const char* name);
-
     /**
      *  Custom class for holding the arguments for a string flag.
      *  Publicly only has accessors so the strings cannot be modified.
@@ -150,6 +141,16 @@
         friend class SkFlagInfo;
     };
 
+    /* Takes a list of the form [~][^]match[$]
+     ~ causes a matching test to always be skipped
+     ^ requires the start of the test to match
+     $ requires the end of the test to match
+     ^ and $ requires an exact match
+     If a test does not match any list entry, it is skipped unless some list entry starts with ~
+    */
+    static bool ShouldSkip(const SkTDArray<const char*>& strings, const char* name);
+    static bool ShouldSkip(const StringArray& strings, const char* name);
+
 private:
     static SkFlagInfo* gHead;
     static SkString    gUsage;