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

Unified Diff: src/record/SkRecordPattern.h

Issue 275623002: Split Star into Star (stores nothing) and List (stores matches). (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: yagni 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 | « no previous file | tests/RecordPatternTest.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 b1334a87c6a2149478205d68d2f62cdfc7ec14ae..57779ffd761f032194302877dbf1fb7f82f31f6b 100644
--- a/src/record/SkRecordPattern.h
+++ b/src/record/SkRecordPattern.h
@@ -85,44 +85,13 @@ struct Or {
template <typename A, typename B, typename C>
struct Or3 : Or<A, Or<B, C> > {};
-// We'll use this to choose which implementation of Star suits each Matcher.
-SK_CREATE_TYPE_DETECTOR(type);
-
-// Star is a special matcher that matches Matcher 0 or more times _greedily_ in the SkRecord.
-// This version stores nothing. It's enabled when Matcher stores nothing.
-template <typename Matcher, typename = void>
-class Star {
-public:
- void reset() {}
-
- template <typename T>
- bool operator()(T* ptr) { return Matcher()(ptr); }
-};
-
-// This version stores a list of matches. It's enabled if Matcher stores something.
+// Star is a special matcher that greedily matches Matcher 0 or more times. Stores nothing.
template <typename Matcher>
-class Star<Matcher, SK_WHEN(HasType_type<Matcher>, void)> {
-public:
- typedef SkTDArray<typename Matcher::type*> type;
- type* get() { return &fMatches; }
-
- void reset() { fMatches.rewind(); }
-
+struct Star {
template <typename T>
- bool operator()(T* ptr) {
- Matcher matcher;
- if (matcher(ptr)) {
- fMatches.push(matcher.get());
- return true;
- }
- return false;
- }
-
-private:
- type fMatches;
+ bool operator()(T* ptr) { return Matcher()(ptr); }
};
-
// Cons builds a list of Matchers.
// It first matches Matcher (something from above), then Pattern (another Cons or Nil).
//
@@ -175,7 +144,6 @@ private:
// If head is a Star, walk i until it doesn't match.
template <typename T>
unsigned matchHead(Star<T>*, SkRecord* record, unsigned i) {
- fHead.reset();
while (i < record->count()) {
if (!record->mutate<bool>(i, fHead)) {
return i;
« no previous file with comments | « no previous file | tests/RecordPatternTest.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698