Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code

Delta Between Two Patch Sets: compiled/Filter.cpp

Issue 29333474: Issue 4125 - [emscripten] Convert filter classes to C++ (Closed)
Left Patch Set: Addressed Sergei`s comments again Created Feb. 23, 2016, 9:29 p.m.
Right Patch Set: Addressed comments from Patch Set 28 Created March 21, 2017, 10:04 a.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
Left: Side by side diff | Download
Right: Side by side diff | Download
« no previous file with change/comment | « compiled/Filter.h ('k') | compiled/InvalidFilter.h » ('j') | no next file with change/comment »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
LEFTRIGHT
1 #include "Filter.h" 1 #include "Filter.h"
2 #include "CommentFilter.h" 2 #include "CommentFilter.h"
3 #include "InvalidFilter.h" 3 #include "InvalidFilter.h"
4 #include "RegExpFilter.h" 4 #include "RegExpFilter.h"
5 #include "BlockingFilter.h" 5 #include "BlockingFilter.h"
6 #include "WhitelistFilter.h" 6 #include "WhitelistFilter.h"
7 #include "ElemHideBase.h" 7 #include "ElemHideBase.h"
8 #include "ElemHideFilter.h" 8 #include "ElemHideFilter.h"
9 #include "ElemHideException.h" 9 #include "ElemHideException.h"
10 #include "CSSPropertyFilter.h" 10 #include "CSSPropertyFilter.h"
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
48 // Remove trailing spaces 48 // Remove trailing spaces
49 for (; end > 0; end--) 49 for (; end > 0; end--)
50 if (text[end - 1] != ' ') 50 if (text[end - 1] != ' ')
51 break; 51 break;
52 52
53 // Set new string boundaries 53 // Set new string boundaries
54 text.reset(text, start, end - start); 54 text.reset(text, start, end - start);
55 } 55 }
56 } 56 }
57 57
58 Filter::Filter(const String& text) 58 Filter::Filter(Type type, const String& text)
59 : mText(text) 59 : mType(type), mText(text)
60 { 60 {
61 annotate_address(this, "Filter"); 61 annotate_address(this, "Filter");
62 } 62 }
63 63
64 Filter::~Filter() 64 Filter::~Filter()
65 { 65 {
66 // TODO: This should be removing from knownFilters 66 knownFilters.erase(mText);
67 } 67 }
68 68
69 OwnedString Filter::Serialize() const 69 OwnedString Filter::Serialize() const
70 { 70 {
71 OwnedString result(u"[Filter]\ntext="_str); 71 OwnedString result(u"[Filter]\ntext="_str);
72 result.append(mText); 72 result.append(mText);
73 result.append(u'\n'); 73 result.append(u'\n');
74 return result; 74 return result;
75 } 75 }
76 76
(...skipping 13 matching lines...) Expand all
90 DependentString error; 90 DependentString error;
91 91
92 Filter::Type type = CommentFilter::Parse(text); 92 Filter::Type type = CommentFilter::Parse(text);
93 if (type == Filter::Type::UNKNOWN) 93 if (type == Filter::Type::UNKNOWN)
94 type = ElemHideBase::Parse(text, data.elemhide); 94 type = ElemHideBase::Parse(text, data.elemhide);
95 if (type == Filter::Type::UNKNOWN) 95 if (type == Filter::Type::UNKNOWN)
96 type = RegExpFilter::Parse(text, error, data.regexp); 96 type = RegExpFilter::Parse(text, error, data.regexp);
97 97
98 auto knownFilter = knownFilters.find(text); 98 auto knownFilter = knownFilters.find(text);
99 if (knownFilter) 99 if (knownFilter)
100 {
101 knownFilter->second->AddRef();
100 return knownFilter->second; 102 return knownFilter->second;
103 }
101 104
102 FilterPtr filter; 105 FilterPtr filter;
103 switch (type) 106 switch (type)
104 { 107 {
105 case Filter::Type::COMMENT: 108 case Filter::Type::COMMENT:
106 filter = new CommentFilter(text); 109 filter = new CommentFilter(text);
107 break; 110 break;
108 case Filter::Type::INVALID: 111 case Filter::Type::INVALID:
109 filter = new InvalidFilter(text, error); 112 filter = new InvalidFilter(text, error);
110 break; 113 break;
(...skipping 19 matching lines...) Expand all
130 return nullptr; 133 return nullptr;
131 } 134 }
132 135
133 // This is a hack: we looked up the entry using text but create it using 136 // This is a hack: we looked up the entry using text but create it using
134 // filter->mText. This works because both are equal at this point. However, 137 // filter->mText. This works because both are equal at this point. However,
135 // text refers to a temporary buffer which will go away. 138 // text refers to a temporary buffer which will go away.
136 enter_context("Adding to known filters"); 139 enter_context("Adding to known filters");
137 knownFilter.assign(filter->mText, filter.get()); 140 knownFilter.assign(filter->mText, filter.get());
138 exit_context(); 141 exit_context();
139 142
140 // TODO: We intentionally leak the filter here - currently it won't be used 143 return filter.release();
141 // for anything and would be deleted immediately.
142 filter->AddRef();
143
144 return filter;
145 } 144 }
146
147 Filter* Filter::GetKnownFilter(const String& text)
148 {
149 auto it = knownFilters.find(text);
150 if (it)
151 return it->second;
152 else
153 return nullptr;
154 }
LEFTRIGHT

Powered by Google App Engine
This is Rietveld