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: Rebased Created April 13, 2017, 1:07 p.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 <type_traits> 20 #include <type_traits>
21 #include <vector> 21 #include <vector>
22 22
23 #include "../filter/Filter.h" 23 #include "../filter/Filter.h"
24 #include "../String.h" 24 #include "../String.h"
25 #include "../FilterNotifier.h"
25 #include "../intrusive_ptr.h" 26 #include "../intrusive_ptr.h"
26 #include "../debug.h" 27 #include "../debug.h"
27 28
28 #define SUBSCRIPTION_PROPERTY(type, name, getter, setter) \ 29 #define SUBSCRIPTION_PROPERTY_INTERNAL(field_type, param_type, name, topic, gett er, setter) \
29 static_assert(std::is_arithmetic<type>::value, "SUBSCRIPTION_PROPERTY macro can only be used with arithmetic types");\
30 private:\ 30 private:\
31 type name;\ 31 field_type name;\
32 public:\ 32 public:\
33 type EMSCRIPTEN_KEEPALIVE getter() const\ 33 param_type EMSCRIPTEN_KEEPALIVE getter() const\
34 {\ 34 {\
35 return name;\ 35 return name;\
36 }\ 36 }\
37 void EMSCRIPTEN_KEEPALIVE setter(type value)\ 37 void EMSCRIPTEN_KEEPALIVE setter(param_type value)\
38 {\ 38 {\
39 if (name != value)\ 39 if (name != value)\
40 {\ 40 {\
41 type oldvalue = name;\ 41 field_type oldvalue = name;\
42 name = value;\ 42 name = value;\
43 DependentString action(u"subscription."_str #name);\ 43 if (FilterNotifier::Topic::topic != FilterNotifier::Topic::NONE)\
44 if (sizeof(type) <= 4)\
45 {\ 44 {\
46 EM_ASM_ARGS({\ 45 FilterNotifier::PropertyChange(FilterNotifier::Topic::topic,\
47 var subscription = new (exports[Subscription_mapping[$2]])($1);\ 46 this, value, oldvalue);\
48 FilterNotifier.triggerListeners(readString($0), subscription, $3, $4);\
49 }, &action, this, mType, value, oldvalue);\
50 }\
51 else\
52 {\
53 EM_ASM_ARGS({\
54 var subscription = new (exports[Subscription_mapping[$2]])($1);\
55 FilterNotifier.triggerListeners(readString($0), subscription, $3, $4);\
56 }, &action, this, mType, (double)value, (double)oldvalue);\
57 }\ 47 }\
58 }\ 48 }\
59 } 49 }
60 50
61 #define SUBSCRIPTION_STRING_PROPERTY(name, getter, setter) \ 51 #define SUBSCRIPTION_PROPERTY(type, name, topic, getter, setter) \
62 private:\ 52 static_assert(std::is_arithmetic<type>::value, "SUBSCRIPTION_PROPERTY macro can only be used with arithmetic types");\
63 OwnedString name;\ 53 SUBSCRIPTION_PROPERTY_INTERNAL(type, type, name, topic, getter, setter)
64 public:\ 54
65 const String& EMSCRIPTEN_KEEPALIVE getter() const\ 55 #define SUBSCRIPTION_STRING_PROPERTY(name, topic, getter, setter) \
66 {\ 56 SUBSCRIPTION_PROPERTY_INTERNAL(OwnedString, const String&, name, topic, gett er, setter)
67 return name;\
68 }\
69 void EMSCRIPTEN_KEEPALIVE setter(const String& value)\
70 {\
71 if (!name.equals(value))\
72 {\
73 OwnedString oldvalue(name);\
74 name = value;\
75 DependentString action(u"subscription."_str #name);\
76 EM_ASM_ARGS({\
77 var subscription = new (exports[Subscription_mapping[$2]])($1);\
78 FilterNotifier.triggerListeners(readString($0), subscription, readSt ring($3), readString($4));\
79 }, &action, this, mType, &value, &oldvalue);\
80 }\
81 }
82 57
83 class Subscription : public ref_counted 58 class Subscription : public ref_counted
84 { 59 {
85 protected: 60 protected:
86 OwnedString mID; 61 OwnedString mID;
87 std::vector<FilterPtr> mFilters; 62 std::vector<FilterPtr> mFilters;
88 63
89 public: 64 public:
90 enum Type 65 enum Type
91 { 66 {
92 UNKNOWN = 0, 67 UNKNOWN = 0,
93 DOWNLOADABLE = 1, 68 DOWNLOADABLE = 1,
94 USERDEFINED = 2 69 USERDEFINED = 2
95 }; 70 };
96 71
97 explicit Subscription(Type type, const String& id); 72 explicit Subscription(Type type, const String& id);
98 ~Subscription(); 73 ~Subscription();
99 74
100 Type mType; 75 Type mType;
101 76
102 EMSCRIPTEN_KEEPALIVE const String& GetID() const 77 EMSCRIPTEN_KEEPALIVE const String& GetID() const
103 { 78 {
104 return mID; 79 return mID;
105 } 80 }
106 81
107 SUBSCRIPTION_STRING_PROPERTY(mTitle, GetTitle, SetTitle); 82 SUBSCRIPTION_STRING_PROPERTY(mTitle, SUBSCRIPTION_TITLE, GetTitle, SetTitle);
108 SUBSCRIPTION_PROPERTY(bool, mDisabled, GetDisabled, SetDisabled); 83 SUBSCRIPTION_PROPERTY(bool, mDisabled, SUBSCRIPTION_DISABLED,
84 GetDisabled, SetDisabled);
109 85
110 EMSCRIPTEN_KEEPALIVE unsigned GetFilterCount() const 86 EMSCRIPTEN_KEEPALIVE unsigned GetFilterCount() const
111 { 87 {
112 return mFilters.size(); 88 return mFilters.size();
113 } 89 }
114 90
115 EMSCRIPTEN_KEEPALIVE Filter* FilterAt(unsigned index); 91 EMSCRIPTEN_KEEPALIVE Filter* FilterAt(unsigned index);
116 EMSCRIPTEN_KEEPALIVE int IndexOfFilter(Filter* filter); 92 EMSCRIPTEN_KEEPALIVE int IndexOfFilter(Filter* filter);
117 EMSCRIPTEN_KEEPALIVE OwnedString Serialize() const; 93 EMSCRIPTEN_KEEPALIVE OwnedString Serialize() const;
118 EMSCRIPTEN_KEEPALIVE OwnedString SerializeFilters() const; 94 EMSCRIPTEN_KEEPALIVE OwnedString SerializeFilters() const;
119 95
120 static EMSCRIPTEN_KEEPALIVE Subscription* FromID(const String& id); 96 static EMSCRIPTEN_KEEPALIVE Subscription* FromID(const String& id);
121 }; 97 };
122 98
123 typedef intrusive_ptr<Subscription> SubscriptionPtr; 99 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