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

Side by Side Diff: compiled/subscription/Subscription.h

Issue 29398669: Issue 5063 - [emscripten] Make FilterNotifier calls more efficient (Closed) Base URL: https://hg.adblockplus.org/adblockpluscore
Patch Set: Created March 30, 2017, 10:08 a.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View unified diff | Download patch
« no previous file with comments | « compiled/subscription/DownloadableSubscription.h ('k') | test/filterClasses.js » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * This file is part of Adblock Plus <https://adblockplus.org/>, 2 * This file is part of Adblock Plus <https://adblockplus.org/>,
3 * Copyright (C) 2006-2017 eyeo GmbH 3 * Copyright (C) 2006-2017 eyeo GmbH
4 * 4 *
5 * Adblock Plus is free software: you can redistribute it and/or modify 5 * Adblock Plus is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License version 3 as 6 * it under the terms of the GNU General Public License version 3 as
7 * published by the Free Software Foundation. 7 * published by the Free Software Foundation.
8 * 8 *
9 * Adblock Plus is distributed in the hope that it will be useful, 9 * Adblock Plus is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details. 12 * GNU General Public License for more details.
13 * 13 *
14 * You should have received a copy of the GNU General Public License 14 * You should have received a copy of the GNU General Public License
15 * along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>. 15 * along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>.
16 */ 16 */
17 17
18 #pragma once 18 #pragma once
19 19
20 #include <vector> 20 #include <vector>
21 21
22 #include "../filter/Filter.h" 22 #include "../filter/Filter.h"
23 #include "../String.h" 23 #include "../String.h"
24 #include "../FilterNotifier.h"
24 #include "../intrusive_ptr.h" 25 #include "../intrusive_ptr.h"
25 #include "../debug.h" 26 #include "../debug.h"
26 27
27 #define SUBSCRIPTION_PROPERTY(type, name, getter, setter) \ 28 #define SUBSCRIPTION_PROPERTY_INTERNAL(field_type, param_type, name, topic, gett er, setter) \
28 private:\ 29 private:\
29 type name;\ 30 field_type name;\
30 public:\ 31 public:\
31 type EMSCRIPTEN_KEEPALIVE getter() const\ 32 param_type EMSCRIPTEN_KEEPALIVE getter() const\
32 {\ 33 {\
33 return name;\ 34 return name;\
34 }\ 35 }\
35 void EMSCRIPTEN_KEEPALIVE setter(type value)\ 36 void EMSCRIPTEN_KEEPALIVE setter(param_type value)\
36 {\ 37 {\
37 if (name != value)\ 38 if (name != value)\
38 {\ 39 {\
39 type oldvalue = name;\ 40 field_type oldvalue = name;\
40 name = value;\ 41 name = value;\
41 DependentString action(u"subscription."_str #name);\ 42 if (FilterNotifier::Topic::topic != FilterNotifier::Topic::NONE)\
42 EM_ASM_ARGS({\ 43 {\
43 var subscription = new (exports[Subscription_mapping[$2]])($1);\ 44 FilterNotifier::PropertyChange(FilterNotifier::Topic::topic,\
44 FilterNotifier.triggerListeners(readString($0), subscription, $3, $4 );\ 45 this, value, oldvalue);\
45 }, &action, this, mType, value, oldvalue);\ 46 }\
46 }\ 47 }\
47 } 48 }
48 49
49 #define SUBSCRIPTION_STRING_PROPERTY(name, getter, setter) \ 50 #define SUBSCRIPTION_PROPERTY(type, name, topic, getter, setter) \
50 private:\ 51 SUBSCRIPTION_PROPERTY_INTERNAL(type, type, name, topic, getter, setter)
51 OwnedString name;\ 52
52 public:\ 53 #define SUBSCRIPTION_STRING_PROPERTY(name, topic, getter, setter) \
53 const String& EMSCRIPTEN_KEEPALIVE getter() const\ 54 SUBSCRIPTION_PROPERTY_INTERNAL(OwnedString, const String&, name, topic, gett er, setter)
54 {\
55 return name;\
56 }\
57 void EMSCRIPTEN_KEEPALIVE setter(const String& value)\
58 {\
59 if (!name.equals(value))\
60 {\
61 OwnedString oldvalue(name);\
62 name = value;\
63 DependentString action(u"subscription."_str #name);\
64 EM_ASM_ARGS({\
65 var subscription = new (exports[Subscription_mapping[$2]])($1);\
66 FilterNotifier.triggerListeners(readString($0), subscription, readSt ring($3), readString($4));\
67 }, &action, this, mType, &value, &oldvalue);\
68 }\
69 }
70 55
71 class Subscription : public ref_counted 56 class Subscription : public ref_counted
72 { 57 {
73 protected: 58 protected:
74 OwnedString mID; 59 OwnedString mID;
75 std::vector<FilterPtr> mFilters; 60 std::vector<FilterPtr> mFilters;
76 61
77 public: 62 public:
78 enum Type 63 enum Type
79 { 64 {
80 UNKNOWN = 0, 65 UNKNOWN = 0,
81 DOWNLOADABLE = 1, 66 DOWNLOADABLE = 1,
82 USERDEFINED = 2 67 USERDEFINED = 2
83 }; 68 };
84 69
85 explicit Subscription(Type type, const String& id); 70 explicit Subscription(Type type, const String& id);
86 ~Subscription(); 71 ~Subscription();
87 72
88 Type mType; 73 Type mType;
89 74
90 EMSCRIPTEN_KEEPALIVE const String& GetID() const 75 EMSCRIPTEN_KEEPALIVE const String& GetID() const
91 { 76 {
92 return mID; 77 return mID;
93 } 78 }
94 79
95 SUBSCRIPTION_STRING_PROPERTY(mTitle, GetTitle, SetTitle); 80 SUBSCRIPTION_STRING_PROPERTY(mTitle, SUBSCRIPTION_TITLE, GetTitle, SetTitle);
96 SUBSCRIPTION_PROPERTY(bool, mDisabled, GetDisabled, SetDisabled); 81 SUBSCRIPTION_PROPERTY(bool, mDisabled, SUBSCRIPTION_DISABLED,
82 GetDisabled, SetDisabled);
97 83
98 EMSCRIPTEN_KEEPALIVE unsigned GetFilterCount() const 84 EMSCRIPTEN_KEEPALIVE unsigned GetFilterCount() const
99 { 85 {
100 return mFilters.size(); 86 return mFilters.size();
101 } 87 }
102 88
103 EMSCRIPTEN_KEEPALIVE Filter* FilterAt(unsigned index); 89 EMSCRIPTEN_KEEPALIVE Filter* FilterAt(unsigned index);
104 EMSCRIPTEN_KEEPALIVE int IndexOfFilter(Filter* filter); 90 EMSCRIPTEN_KEEPALIVE int IndexOfFilter(Filter* filter);
105 EMSCRIPTEN_KEEPALIVE OwnedString Serialize() const; 91 EMSCRIPTEN_KEEPALIVE OwnedString Serialize() const;
106 EMSCRIPTEN_KEEPALIVE OwnedString SerializeFilters() const; 92 EMSCRIPTEN_KEEPALIVE OwnedString SerializeFilters() const;
107 93
108 static EMSCRIPTEN_KEEPALIVE Subscription* FromID(const String& id); 94 static EMSCRIPTEN_KEEPALIVE Subscription* FromID(const String& id);
109 }; 95 };
110 96
111 typedef intrusive_ptr<Subscription> SubscriptionPtr; 97 typedef intrusive_ptr<Subscription> SubscriptionPtr;
OLDNEW
« no previous file with comments | « compiled/subscription/DownloadableSubscription.h ('k') | test/filterClasses.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld