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: 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/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 INT64 = 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, (sizeof(T) <= 4 ? newValue : (double)newValue),
60 (sizeof(T) <= 4 ? oldValue : (double)oldValue), type);
61 }
62
63 template void NotifyPropertyChange<int>(FilterNotifier::Topic, void*,
64 int, int, ArgType);
65
66 template void NotifyPropertyChange<double>(FilterNotifier::Topic, void*,
67 double, double, ArgType);
68 }
69
70 namespace FilterNotifier
71 {
72 void PropertyChange(Topic topic, void* object, bool newValue, bool oldValue)
73 {
74 NotifyPropertyChange<int>(topic, object, newValue, oldValue, ArgType::BOOL);
75 }
76
77 void PropertyChange(Topic topic, void* object, int newValue, int oldValue)
78 {
79 NotifyPropertyChange<int>(topic, object, newValue, oldValue, ArgType::INT);
80 }
81
82 void PropertyChange(Topic topic, void* object, unsigned int newValue,
83 unsigned int oldValue)
84 {
85 NotifyPropertyChange<int>(topic, object, newValue, oldValue, ArgType::INT);
86 }
87
88 void PropertyChange(Topic topic, void* object, uint64_t newValue,
89 uint64_t oldValue)
90 {
91 NotifyPropertyChange<uint64_t>(topic, object, newValue, oldValue,
92 ArgType::INT64);
93 }
94
95 void PropertyChange(Topic topic, void* object, const String& newValue,
96 const String& oldValue)
97 {
98 NotifyPropertyChange<int>(topic, object, reinterpret_cast<int>(&newValue),
99 reinterpret_cast<int>(&oldValue), ArgType::STRING) ;
100 }
101 }
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