Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
gorhill committed Dec 8, 2017
1 parent 4b70553 commit c7e8b65
Showing 1 changed file with 4 additions and 10 deletions.
14 changes: 4 additions & 10 deletions src/js/hntrie.js
Original file line number Diff line number Diff line change
Expand Up @@ -184,19 +184,13 @@ HNTrieBuilder.prototype.add = function(hn) {
*/

HNTrieBuilder.prototype.fromDomainOpt = function(hostnames) {
var len = hostnames.length,
beg = 0, end;
while ( beg < len ) {
end = hostnames.indexOf('|', beg);
if ( end === -1 ) { end = len; }
this.add(hostnames.slice(beg, end));
beg = end + 1;
}
return this;
return this.fromIterable(hostnames.split('|'));
};

HNTrieBuilder.prototype.fromIterable = function(hostnames) {
for ( var hn of hostnames ) {
// https://github.com/gorhill/uBlock/issues/3328
// Must sort from shortest to longest.
for ( var hn of hostnames.sort(function(a,b){return a.length-b.length;}) ) {
this.add(hn);
}
return this;
Expand Down

0 comments on commit c7e8b65

Please sign in to comment.