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

Delta Between Two Patch Sets: lib/filterClasses.js

Issue 29871555: Issue 6916 - Avoid Set object for filters with only one subscription (Closed) Base URL: https://hg.adblockplus.org/adblockpluscore/
Left Patch Set: Rebase Created Sept. 1, 2018, 2:28 p.m.
Right Patch Set: Add type check to addSubscription Created Sept. 1, 2018, 2:43 p.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 | « no previous file | no next file » | 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-present eyeo GmbH 3 * Copyright (C) 2006-present 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
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
62 * Filter type as a string, e.g. "blocking". 62 * Filter type as a string, e.g. "blocking".
63 * @type {string} 63 * @type {string}
64 */ 64 */
65 get type() 65 get type()
66 { 66 {
67 throw new Error("Please define filter type in the subclass"); 67 throw new Error("Please define filter type in the subclass");
68 }, 68 },
69 69
70 /** 70 /**
71 * Yields subscriptions to which the filter belongs. 71 * Yields subscriptions to which the filter belongs.
72 * @yields {Subscription} 72 * @yields {Subscription}
Jon Sonesen 2018/09/02 17:22:50 Should this be {(Subscription|Set.<Subscription>)?
Manish Jethani 2018/09/03 19:03:42 No, the function only ever yields a single Subscri
73 */ 73 */
74 *subscriptions() 74 *subscriptions()
75 { 75 {
76 if (this._subscriptions) 76 if (this._subscriptions)
77 { 77 {
78 if (this._subscriptions instanceof Set) 78 if (this._subscriptions instanceof Set)
79 yield* this._subscriptions; 79 yield* this._subscriptions;
80 else 80 else
81 yield this._subscriptions; 81 yield this._subscriptions;
82 } 82 }
(...skipping 11 matching lines...) Expand all
94 return this._subscriptions ? 1 : 0; 94 return this._subscriptions ? 1 : 0;
95 }, 95 },
96 96
97 /** 97 /**
98 * Adds a subscription to the set of subscriptions to which the filter 98 * Adds a subscription to the set of subscriptions to which the filter
99 * belongs. 99 * belongs.
100 * @param {Subscription} subscription 100 * @param {Subscription} subscription
101 */ 101 */
102 addSubscription(subscription) 102 addSubscription(subscription)
103 { 103 {
104 // Since we use truthy checks in our logic, we must avoid adding a
105 // subscription that isn't a non-null object.
Jon Sonesen 2018/09/02 17:22:50 the double negative in the comment is sort of conf
Manish Jethani 2018/09/03 19:03:42 The non-null part is a bit of a distraction: the p
106 if (subscription === null || typeof subscription != "object")
107 return;
108
104 if (this._subscriptions) 109 if (this._subscriptions)
105 { 110 {
106 if (this._subscriptions instanceof Set) 111 if (this._subscriptions instanceof Set)
107 this._subscriptions.add(subscription); 112 this._subscriptions.add(subscription);
108 else if (subscription != this._subscriptions) 113 else if (subscription != this._subscriptions)
109 this._subscriptions = new Set([this._subscriptions, subscription]); 114 this._subscriptions = new Set([this._subscriptions, subscription]);
110 } 115 }
111 else 116 else
112 { 117 {
113 this._subscriptions = subscription; 118 this._subscriptions = subscription;
114 } 119 }
115 }, 120 },
116 121
117 /** 122 /**
118 * Removes a subscription from the set of subscriptions to which the filter 123 * Removes a subscription from the set of subscriptions to which the filter
119 * belongs. 124 * belongs.
120 * @param {Subscription} subscription 125 * @param {Subscription} subscription
121 */ 126 */
122 removeSubscription(subscription) 127 removeSubscription(subscription)
123 { 128 {
124 if (this._subscriptions) 129 if (this._subscriptions)
125 { 130 {
126 if (this._subscriptions instanceof Set) 131 if (this._subscriptions instanceof Set)
127 { 132 {
128 this._subscriptions.delete(subscription); 133 this._subscriptions.delete(subscription);
129 134
130 if (this._subscriptions.size == 1) 135 if (this._subscriptions.size == 1)
131 this._subscriptions = [...this._subscriptions][0]; 136 this._subscriptions = [...this._subscriptions][0];
Jon Sonesen 2018/09/02 17:22:50 Just asking, not so much a comment but this line
Manish Jethani 2018/09/03 19:03:42 Yes, that's exactly what it does. We can't do `thi
132 } 137 }
133 else if (subscription == this._subscriptions) 138 else if (subscription == this._subscriptions)
134 { 139 {
135 this._subscriptions = null; 140 this._subscriptions = null;
136 } 141 }
137 } 142 }
138 }, 143 },
139 144
140 /** 145 /**
141 * Serializes the filter to an array of strings for writing out on the disk. 146 * Serializes the filter to an array of strings for writing out on the disk.
(...skipping 1105 matching lines...) Expand 10 before | Expand all | Expand 10 after
1247 1252
1248 /** 1253 /**
1249 * Script that should be executed 1254 * Script that should be executed
1250 * @type {string} 1255 * @type {string}
1251 */ 1256 */
1252 get script() 1257 get script()
1253 { 1258 {
1254 return this.body; 1259 return this.body;
1255 } 1260 }
1256 }); 1261 });
LEFTRIGHT
« no previous file | no next file » | Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Toggle Comments ('s')

Powered by Google App Engine
This is Rietveld