Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(51)

Unified Diff: src/record/SkRecordPattern.h

Issue 273643007: Convert all SkRecordPattern matchers into SkRecord mutators. (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: dumper too Created 6 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « src/record/SkRecordOpts.cpp ('k') | tests/RecordOptsTest.cpp » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/record/SkRecordPattern.h
diff --git a/src/record/SkRecordPattern.h b/src/record/SkRecordPattern.h
index c5d87f2a20aeaa4cae597525e8e0f7734d42e3ad..b1334a87c6a2149478205d68d2f62cdfc7ec14ae 100644
--- a/src/record/SkRecordPattern.h
+++ b/src/record/SkRecordPattern.h
@@ -17,13 +17,13 @@ public:
typedef T type;
type* get() { return fPtr; }
- bool match(T* ptr) {
+ bool operator()(T* ptr) {
fPtr = ptr;
return true;
}
template <typename U>
- bool match(U*) {
+ bool operator()(U*) {
fPtr = NULL;
return false;
}
@@ -42,19 +42,19 @@ public:
type* get() { return fPaint; }
template <typename T>
- SK_WHEN(HasMember_paint<T>, bool) match(T* draw) {
+ SK_WHEN(HasMember_paint<T>, bool) operator()(T* draw) {
fPaint = AsPtr(draw->paint);
return true;
}
template <typename T>
- SK_WHEN(!HasMember_paint<T>, bool) match(T*) {
+ SK_WHEN(!HasMember_paint<T>, bool) operator()(T*) {
fPaint = NULL;
return false;
}
// SaveLayer has an SkPaint named paint, but it's not a draw.
- bool match(SaveLayer*) {
+ bool operator()(SaveLayer*) {
fPaint = NULL;
return false;
}
@@ -71,14 +71,14 @@ private:
template <typename Matcher>
struct Not {
template <typename T>
- bool match(T* ptr) { return !Matcher().match(ptr); }
+ bool operator()(T* ptr) { return !Matcher()(ptr); }
};
// Matches if either of A or B does. Stores nothing.
template <typename A, typename B>
struct Or {
template <typename T>
- bool match(T* ptr) { return A().match(ptr) || B().match(ptr); }
+ bool operator()(T* ptr) { return A()(ptr) || B()(ptr); }
};
// Matches if any of A, B or C does. Stores nothing.
@@ -96,7 +96,7 @@ public:
void reset() {}
template <typename T>
- bool match(T* ptr) { return Matcher().match(ptr); }
+ bool operator()(T* ptr) { return Matcher()(ptr); }
};
// This version stores a list of matches. It's enabled if Matcher stores something.
@@ -109,9 +109,9 @@ public:
void reset() { fMatches.rewind(); }
template <typename T>
- bool match(T* ptr) {
+ bool operator()(T* ptr) {
Matcher matcher;
- if (matcher.match(ptr)) {
+ if (matcher(ptr)) {
fMatches.push(matcher.get());
return true;
}
@@ -161,16 +161,11 @@ public:
template <typename T> T* third() { return fTail.fTail.fHead.get(); }
private:
- template <typename T>
- void operator()(T* r) { fHeadMatched = fHead.match(r); }
-
// If head isn't a Star, try to match at i once.
template <typename T>
unsigned matchHead(T*, SkRecord* record, unsigned i) {
if (i < record->count()) {
- fHeadMatched = false;
- record->mutate(i, *this);
- if (fHeadMatched) {
+ if (record->mutate<bool>(i, fHead)) {
return i+1;
}
}
@@ -182,9 +177,7 @@ private:
unsigned matchHead(Star<T>*, SkRecord* record, unsigned i) {
fHead.reset();
while (i < record->count()) {
- fHeadMatched = false;
- record->mutate(i, *this);
- if (!fHeadMatched) {
+ if (!record->mutate<bool>(i, fHead)) {
return i;
}
i++;
@@ -194,9 +187,6 @@ private:
Matcher fHead;
Pattern fTail;
- bool fHeadMatched;
-
- friend class ::SkRecord; // So operator() can otherwise stay private.
// All Cons are friends with each other. This lets first, second, and third work.
template <typename, typename> friend class Cons;
« no previous file with comments | « src/record/SkRecordOpts.cpp ('k') | tests/RecordOptsTest.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698