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

Unified Diff: lib/matcher.js

Issue 29897555: Issue 6940 - Use underscore prefixes lib/matcher.js (Closed)
Patch Set: Rebase Created Oct. 21, 2018, 3:04 a.m.
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | test/filterListener.js » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: lib/matcher.js
===================================================================
--- a/lib/matcher.js
+++ b/lib/matcher.js
@@ -52,95 +52,97 @@
* Blacklist/whitelist filter matching
*/
class Matcher
{
constructor()
{
/**
* Lookup table for filters by their associated keyword
+ * @private
Manish Jethani 2018/10/21 12:12:19 I've already started using @private/@protected els
Jon Sonesen 2018/10/23 01:28:01 Acknowledged.
* @type {Map.<string,(Filter|Set.<Filter>)>}
*/
- this.filterByKeyword = new Map();
+ this._filterByKeyword = new Map();
}
/**
* Removes all known filters
*/
clear()
{
- this.filterByKeyword.clear();
+ this._filterByKeyword.clear();
}
/**
* Adds a filter to the matcher
* @param {RegExpFilter} filter
*/
add(filter)
{
// Look for a suitable keyword
let keyword = this.findKeyword(filter);
- let set = this.filterByKeyword.get(keyword);
+ let set = this._filterByKeyword.get(keyword);
if (typeof set == "undefined")
{
- this.filterByKeyword.set(keyword, filter);
+ this._filterByKeyword.set(keyword, filter);
}
else if (set.size == 1)
{
if (filter != set)
- this.filterByKeyword.set(keyword, new Set([set, filter]));
+ this._filterByKeyword.set(keyword, new Set([set, filter]));
}
else
{
set.add(filter);
}
}
/**
* Removes a filter from the matcher
* @param {RegExpFilter} filter
*/
remove(filter)
{
let keyword = this.findKeyword(filter);
- let set = this.filterByKeyword.get(keyword);
+ let set = this._filterByKeyword.get(keyword);
if (typeof set == "undefined")
return;
if (set.size == 1)
{
if (filter == set)
- this.filterByKeyword.delete(keyword);
+ this._filterByKeyword.delete(keyword);
}
else
{
set.delete(filter);
if (set.size == 1)
- this.filterByKeyword.set(keyword, [...set][0]);
+ this._filterByKeyword.set(keyword, [...set][0]);
}
}
/**
* Chooses a keyword to be associated with the filter
+ * @protected
Manish Jethani 2018/10/21 12:12:19 Same here.
Jon Sonesen 2018/10/23 01:28:04 Acknowledged.
* @param {Filter} filter
* @returns {string} keyword or an empty string if no keyword could be found
*/
findKeyword(filter)
{
let result = "";
let {pattern} = filter;
if (pattern == null)
return result;
let candidates = pattern.toLowerCase().match(allKeywordsRegExp);
if (!candidates)
return result;
- let hash = this.filterByKeyword;
+ let hash = this._filterByKeyword;
let resultCount = 0xFFFFFF;
let resultLength = 0;
for (let i = 0, l = candidates.length; i < l; i++)
{
let candidate = candidates[i].substr(1);
let filters = hash.get(candidate);
let count = typeof filters != "undefined" ? filters.size : 0;
if (count < resultCount ||
@@ -163,17 +165,17 @@
* @param {boolean} [thirdParty]
* @param {string} [sitekey]
* @param {boolean} [specificOnly]
* @returns {?Filter}
*/
_checkEntryMatch(keyword, location, typeMask, docDomain, thirdParty, sitekey,
Manish Jethani 2018/10/21 12:52:04 About this function, I think we can make it "prote
Jon Sonesen 2018/10/23 01:28:02 Acknowledged.
specificOnly)
{
- let set = this.filterByKeyword.get(keyword);
+ let set = this._filterByKeyword.get(keyword);
if (typeof set == "undefined")
return null;
for (let filter of set)
{
if (specificOnly && filter.isGeneric() &&
!(filter instanceof WhitelistFilter))
continue;
« no previous file with comments | « no previous file | test/filterListener.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld