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
This commit is contained in:
commit-bot@chromium.org 2013-08-30 15:52:46 +00:00
parent 06f0598957
commit a6f37e77c1
6 changed files with 27 additions and 32 deletions

View File

@ -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;
}

View File

@ -69,7 +69,6 @@ private:
SkExample* fCurrExample;
const SkExample::Registry* fRegistry;
SkTDArray<const char*> fMatchStrs;
GrContext* fContext;
GrRenderTarget* fRenderTarget;
AttachmentInfo fAttachmentInfo;

View File

@ -2093,13 +2093,6 @@ static bool parse_flags_gmmain_paths(GMMain* gmmain) {
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 @@ int tool_main(int argc, char** argv) {
#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 @@ 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;
}

View File

@ -208,15 +208,10 @@ int tool_main(int argc, char** argv) {
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 @@ int tool_main(int argc, char** argv) {
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();

View File

@ -304,7 +304,10 @@ void SkCommandLineFlags::Parse(int argc, char** argv) {
}
}
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 @@ bool SkCommandLineFlags::ShouldSkip(const SkTDArray<const char*>& strings, const
}
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);
}

View File

@ -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<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 @@ 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<const char*>& strings, const char* name);
static bool ShouldSkip(const StringArray& strings, const char* name);
private:
static SkFlagInfo* gHead;
static SkString gUsage;