Skip to content
This repository has been archived by the owner on Nov 15, 2017. It is now read-only.

Commit

Permalink
avoid having to look up domain if possible
Browse files Browse the repository at this point in the history
  • Loading branch information
gorhill committed May 16, 2014
1 parent 4095bb5 commit 7a41aef
Showing 1 changed file with 15 additions and 13 deletions.
28 changes: 15 additions & 13 deletions js/uritools.js
Original file line number Diff line number Diff line change
Expand Up @@ -363,21 +363,23 @@ URI.parentHostnamesFromHostname = function(hostname) {
// the list of hostnames by making it reusable (junkyard etc.) and which
// has its own element counter property in order to avoid memory
// alloc/dealloc.
var nodes = [];
var pos = hostname.indexOf('.');
if ( pos < 0 ) {
return [];
}
hostname = hostname.slice(pos + 1);
var domain = this.domainFromHostname(hostname);
if ( domain && domain !== hostname ) {
var pos;
while ( true ) {
pos = hostname.indexOf('.');
if ( pos < 0 ) {
break;
}
hostname = hostname.slice(pos + 1);
nodes.push(hostname);
if ( hostname === domain ) {
break;
}
if ( domain === '' ) {
return [];
}
var nodes = [hostname];
while ( hostname !== domain ) {
pos = hostname.indexOf('.');
if ( pos < 0 ) {
break;
}
hostname = hostname.slice(pos + 1);
nodes.push(hostname);
}
return nodes;
};
Expand Down

0 comments on commit 7a41aef

Please sign in to comment.