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

Delta Between Two Patch Sets: compiled/FilterNotifier.cpp

Issue 29398669: Issue 5063 - [emscripten] Make FilterNotifier calls more efficient (Closed) Base URL: https://hg.adblockplus.org/adblockpluscore
Left Patch Set: Added missing files Created April 6, 2017, 8:08 a.m.
Right Patch Set: Addressed comments Created April 20, 2017, 8 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/FilterNotifier.h ('k') | compiled/String.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 /* 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 #include <emscripten.h> 18 #include <emscripten.h>
19 19
20 #include "FilterNotifier.h" 20 #include "FilterNotifier.h"
21 21
22 namespace 22 void FilterNotifier::FilterChange(Topic topic, Filter* filter)
23 { 23 {
24 enum class ArgType 24 EM_ASM_ARGS({
25 { 25 FilterNotifier.triggerListeners(notifierTopics.get($0),
26 BOOL = 0, 26 exports.Filter.fromPointer($1));
27 INT = 1, 27 }, topic, filter);
28 DOUBLE = 2,
29 STRING = 3,
30 };
31
32 template<typename T>
33 void NotifyPropertyChange(FilterNotifier::Topic topic, void* object,
34 T newValue, T oldValue, ArgType type)
35 {
36 EM_ASM_ARGS({
37 var topic = notifierTopics.get($0);
38 var object = topic.startsWith("subscription.") ?
39 exports.Subscription.fromPointer($1) :
40 exports.Filter.fromPointer($1);
41 var newValue;
42 var oldValue;
43 if ($4 == 0)
44 {
45 newValue = $2 != 0;
46 oldValue = $3 != 0;
47 }
48 else if ($4 == 3)
49 {
50 newValue = readString($2);
51 oldValue = readString($3);
52 }
53 else
54 {
55 newValue = $2;
56 oldValue = $3;
57 }
58 FilterNotifier.triggerListeners(topic, object, newValue, oldValue);
59 }, topic, object, newValue, oldValue, type);
60 }
61
62 template void NotifyPropertyChange<int>(FilterNotifier::Topic, void*,
63 int, int, ArgType);
64
65 template void NotifyPropertyChange<double>(FilterNotifier::Topic, void*,
66 double, double, ArgType);
67 } 28 }
68 29
69 namespace FilterNotifier 30 void FilterNotifier::SubscriptionChange(Topic topic, Subscription* subscription)
70 { 31 {
71 void PropertyChange(Topic topic, void* object, bool newValue, bool oldValue) 32 EM_ASM_ARGS({
72 { 33 FilterNotifier.triggerListeners(notifierTopics.get($0),
73 NotifyPropertyChange<int>(topic, object, newValue, oldValue, ArgType::BOOL); 34 exports.Subscription.fromPointer($1));
74 } 35 }, topic, subscription);
75
76 void PropertyChange(Topic topic, void* object, int newValue, int oldValue)
77 {
78 NotifyPropertyChange<int>(topic, object, newValue, oldValue, ArgType::INT);
79 }
80
81 void PropertyChange(Topic topic, void* object, unsigned int newValue,
82 unsigned int oldValue)
83 {
84 NotifyPropertyChange<int>(topic, object, newValue, oldValue, ArgType::INT);
85 }
86
87 void PropertyChange(Topic topic, void* object, double newValue, double oldValu e)
88 {
89 NotifyPropertyChange<double>(topic, object, newValue, oldValue,
90 ArgType::DOUBLE);
91 }
92
93 void PropertyChange(Topic topic, void* object, const String& newValue,
94 const String& oldValue)
95 {
96 NotifyPropertyChange<int>(topic, object, reinterpret_cast<int>(&newValue),
97 reinterpret_cast<int>(&oldValue), ArgType::STRING) ;
98 }
99 } 36 }
LEFTRIGHT

Powered by Google App Engine
This is Rietveld