From a6f37e77c1c95f0a06ac55ff659cb7b8dfabefcf Mon Sep 17 00:00:00 2001 From: "commit-bot@chromium.org" Date: Fri, 30 Aug 2013 15:52:46 +0000 Subject: [PATCH] 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 --- experimental/SkiaExamples/SkExample.cpp | 5 +---- experimental/SkiaExamples/SkExample.h | 1 - gm/gmmain.cpp | 11 +---------- tests/skia_test.cpp | 9 ++------- tools/flags/SkCommandLineFlags.cpp | 14 +++++++++++++- tools/flags/SkCommandLineFlags.h | 19 ++++++++++--------- 6 files changed, 27 insertions(+), 32 deletions(-) diff --git a/experimental/SkiaExamples/SkExample.cpp b/experimental/SkiaExamples/SkExample.cpp index d3601e1cac..d4adaf4924 100644 --- a/experimental/SkiaExamples/SkExample.cpp +++ b/experimental/SkiaExamples/SkExample.cpp @@ -42,9 +42,6 @@ SkExampleWindow::SkExampleWindow(void* hwnd) 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 @@ bool SkExampleWindow::findNextMatch() { 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 8efd309a07..51fe21c06c 100644 --- a/experimental/SkiaExamples/SkExample.h +++ b/experimental/SkiaExamples/SkExample.h @@ -69,7 +69,6 @@ private: SkExample* fCurrExample; const SkExample::Registry* fRegistry; - SkTDArray fMatchStrs; GrContext* fContext; GrRenderTarget* fRenderTarget; AttachmentInfo fAttachmentInfo; diff --git a/gm/gmmain.cpp b/gm/gmmain.cpp index 6fd96f9d24..c24d9c70e4 100644 --- a/gm/gmmain.cpp +++ b/gm/gmmain.cpp @@ -2093,13 +2093,6 @@ static bool parse_flags_gmmain_paths(GMMain* gmmain) { return true; } -static bool parse_flags_match_strs(SkTDArray* 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 @@ int tool_main(int argc, char** argv) { #else GrContextFactory* grFactory = NULL; #endif - SkTDArray matchStrs; if (!parse_flags_modulo(&moduloRemainder, &moduloDivisor) || !parse_flags_ignore_error_types(&gmmain.fIgnorableErrorTypes) || @@ -2154,7 +2146,6 @@ int tool_main(int argc, char** argv) { #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 @@ int tool_main(int argc, char** argv) { 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 a2f5e9c47b..7d22ff69ac 100644 --- a/tests/skia_test.cpp +++ b/tests/skia_test.cpp @@ -208,15 +208,10 @@ int tool_main(int argc, char** argv) { int toRun = 0; Test* test; - SkTDArray matchStrs; - for(int i = 0; i < FLAGS_match.count(); ++i) { - matchStrs.push(FLAGS_match[i]); - } - while ((test = iter.next()) != NULL) { SkAutoTDelete owned(test); - if(!SkCommandLineFlags::ShouldSkip(matchStrs, test->getName())) { + if(!SkCommandLineFlags::ShouldSkip(FLAGS_match, test->getName())) { toRun++; } total++; @@ -232,7 +227,7 @@ int tool_main(int argc, char** argv) { SkTArray unsafeTests; // Always passes ownership to an SkTestRunnable for (int i = 0; i < total; i++) { SkAutoTDelete 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 084f48a8aa..656a00a76d 100644 --- a/tools/flags/SkCommandLineFlags.cpp +++ b/tools/flags/SkCommandLineFlags.cpp @@ -304,7 +304,10 @@ void SkCommandLineFlags::Parse(int argc, char** argv) { } } -bool SkCommandLineFlags::ShouldSkip(const SkTDArray& strings, const char* name) { +namespace { + +template +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 @@ bool SkCommandLineFlags::ShouldSkip(const SkTDArray& strings, const } return !anyExclude; } + +} // namespace + +bool SkCommandLineFlags::ShouldSkip(const SkTDArray& 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 b0199f6717..c324a1f6d0 100644 --- a/tools/flags/SkCommandLineFlags.h +++ b/tools/flags/SkCommandLineFlags.h @@ -108,15 +108,6 @@ public: */ 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& 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 @@ public: 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& strings, const char* name); + static bool ShouldSkip(const StringArray& strings, const char* name); + private: static SkFlagInfo* gHead; static SkString gUsage;