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

Unified Diff: lib/matcher.js

Issue 29804575: Noissue - Remove unnecessary typeof checks in lib/matcher.js (Closed) Base URL: https://hg.adblockplus.org/adblockpluscore/
Patch Set: Created June 12, 2018, 4:47 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 | no next file » | 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
@@ -63,33 +63,33 @@
add(filter)
{
if (this.keywordByFilter.has(filter))
return;
// Look for a suitable keyword
let keyword = this.findKeyword(filter);
let oldEntry = this.filterByKeyword.get(keyword);
- if (typeof oldEntry == "undefined")
+ if (!oldEntry)
this.filterByKeyword.set(keyword, filter);
else if (oldEntry.length == 1)
this.filterByKeyword.set(keyword, [oldEntry, filter]);
else
oldEntry.push(filter);
this.keywordByFilter.set(filter, keyword);
},
/**
* Removes a filter from the matcher
* @param {RegExpFilter} filter
*/
remove(filter)
{
let keyword = this.keywordByFilter.get(filter);
- if (typeof keyword == "undefined")
+ if (keyword == null)
Manish Jethani 2018/06/12 04:50:27 keyword can be an empty string, so we must check a
return;
let list = this.filterByKeyword.get(keyword);
if (list.length <= 1)
this.filterByKeyword.delete(keyword);
else
{
let index = list.indexOf(filter);
@@ -133,17 +133,17 @@
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.length : 0;
+ let count = filters ? filters.length : 0;
if (count < resultCount ||
(count == resultCount && candidate.length > resultLength))
{
result = candidate;
resultCount = count;
resultLength = candidate.length;
}
}
@@ -163,17 +163,17 @@
/**
* Returns the keyword used for a filter, null for unknown filters.
* @param {RegExpFilter} filter
* @return {?string}
*/
getKeywordForFilter(filter)
{
let keyword = this.keywordByFilter.get(filter);
- return typeof keyword != "undefined" ? keyword : null;
+ return keyword != null ? keyword : null;
},
/**
* Checks whether the entries for a particular keyword match a URL
* @param {string} keyword
* @param {string} location
* @param {number} typeMask
* @param {string} docDomain
@@ -181,17 +181,17 @@
* @param {string} sitekey
* @param {boolean} specificOnly
* @return {?Filter}
*/
_checkEntryMatch(keyword, location, typeMask, docDomain, thirdParty, sitekey,
specificOnly)
{
let list = this.filterByKeyword.get(keyword);
- if (typeof list == "undefined")
+ if (!list)
return null;
for (let i = 0; i < list.length; i++)
{
let filter = list[i];
if (specificOnly && filter.isGeneric() &&
!(filter instanceof WhitelistFilter))
continue;
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld