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

Side by Side Diff: compiled/FilterNotifier.cpp

Issue 29398669: Issue 5063 - [emscripten] Make FilterNotifier calls more efficient (Closed) Base URL: https://hg.adblockplus.org/adblockpluscore
Patch Set: Added missing files Created April 6, 2017, 8: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/FilterNotifier.h ('k') | compiled/String.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 /*
2 * This file is part of Adblock Plus <https://adblockplus.org/>,
3 * Copyright (C) 2006-2017 eyeo GmbH
4 *
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
7 * published by the Free Software Foundation.
8 *
9 * Adblock Plus is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
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/>.
16 */
17
18 #include <emscripten.h>
19
20 #include "FilterNotifier.h"
21
22 namespace
23 {
24 enum class ArgType
25 {
26 BOOL = 0,
27 INT = 1,
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 }
68
69 namespace FilterNotifier
70 {
71 void PropertyChange(Topic topic, void* object, bool newValue, bool oldValue)
72 {
73 NotifyPropertyChange<int>(topic, object, newValue, oldValue, ArgType::BOOL);
74 }
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 }
OLDNEW
« no previous file with comments | « compiled/FilterNotifier.h ('k') | compiled/String.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld