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: Removed newValue and oldValue parameters Created April 15, 2017, 3:05 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
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;\
42 name = value;\ 41 name = value;\
43 DependentString action(u"subscription."_str #name);\ 42 if (FilterNotifier::Topic::topic != FilterNotifier::Topic::NONE)\
44 if (sizeof(type) <= 4)\
45 {\ 43 {\
46 EM_ASM_ARGS({\ 44 FilterNotifier::SubscriptionChange(FilterNotifier::Topic::topic,\
47 var subscription = new (exports[Subscription_mapping[$2]])($1);\ 45 this);\
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 }\ 46 }\
58 }\ 47 }\
59 } 48 }
60 49
61 #define SUBSCRIPTION_STRING_PROPERTY(name, getter, setter) \ 50 #define SUBSCRIPTION_PROPERTY(type, name, topic, getter, setter) \
62 private:\ 51 static_assert(std::is_arithmetic<type>::value, "SUBSCRIPTION_PROPERTY macro can only be used with arithmetic types");\
63 OwnedString name;\ 52 SUBSCRIPTION_PROPERTY_INTERNAL(type, type, name, topic, getter, setter)
64 public:\ 53
65 const String& EMSCRIPTEN_KEEPALIVE getter() const\ 54 #define SUBSCRIPTION_STRING_PROPERTY(name, topic, getter, setter) \
66 {\ 55 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 56
83 class Subscription : public ref_counted 57 class Subscription : public ref_counted
84 { 58 {
85 protected: 59 protected:
86 OwnedString mID; 60 OwnedString mID;
87 std::vector<FilterPtr> mFilters; 61 std::vector<FilterPtr> mFilters;
88 62
89 public: 63 public:
90 enum Type 64 enum Type
91 { 65 {
92 UNKNOWN = 0, 66 UNKNOWN = 0,
93 DOWNLOADABLE = 1, 67 DOWNLOADABLE = 1,
94 USERDEFINED = 2 68 USERDEFINED = 2
95 }; 69 };
96 70
97 explicit Subscription(Type type, const String& id); 71 explicit Subscription(Type type, const String& id);
98 ~Subscription(); 72 ~Subscription();
99 73
100 Type mType; 74 Type mType;
101 75
102 EMSCRIPTEN_KEEPALIVE const String& GetID() const 76 EMSCRIPTEN_KEEPALIVE const String& GetID() const
103 { 77 {
104 return mID; 78 return mID;
105 } 79 }
106 80
107 SUBSCRIPTION_STRING_PROPERTY(mTitle, GetTitle, SetTitle); 81 SUBSCRIPTION_STRING_PROPERTY(mTitle, SUBSCRIPTION_TITLE, GetTitle, SetTitle);
108 SUBSCRIPTION_PROPERTY(bool, mDisabled, GetDisabled, SetDisabled); 82 SUBSCRIPTION_PROPERTY(bool, mDisabled, SUBSCRIPTION_DISABLED,
83 GetDisabled, SetDisabled);
109 84
110 EMSCRIPTEN_KEEPALIVE unsigned GetFilterCount() const 85 EMSCRIPTEN_KEEPALIVE unsigned GetFilterCount() const
111 { 86 {
112 return mFilters.size(); 87 return mFilters.size();
113 } 88 }
114 89
115 EMSCRIPTEN_KEEPALIVE Filter* FilterAt(unsigned index); 90 EMSCRIPTEN_KEEPALIVE Filter* FilterAt(unsigned index);
116 EMSCRIPTEN_KEEPALIVE int IndexOfFilter(Filter* filter); 91 EMSCRIPTEN_KEEPALIVE int IndexOfFilter(Filter* filter);
117 EMSCRIPTEN_KEEPALIVE OwnedString Serialize() const; 92 EMSCRIPTEN_KEEPALIVE OwnedString Serialize() const;
118 EMSCRIPTEN_KEEPALIVE OwnedString SerializeFilters() const; 93 EMSCRIPTEN_KEEPALIVE OwnedString SerializeFilters() const;
119 94
120 static EMSCRIPTEN_KEEPALIVE Subscription* FromID(const String& id); 95 static EMSCRIPTEN_KEEPALIVE Subscription* FromID(const String& id);
121 }; 96 };
122 97
123 typedef intrusive_ptr<Subscription> SubscriptionPtr; 98 typedef intrusive_ptr<Subscription> SubscriptionPtr;
OLDNEW

Powered by Google App Engine
This is Rietveld