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

Commit 7a41aef

Browse files
committed
avoid having to look up domain if possible
1 parent 4095bb5 commit 7a41aef

File tree

1 file changed

+15
-13
lines changed

1 file changed

+15
-13
lines changed

js/uritools.js

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -363,21 +363,23 @@ URI.parentHostnamesFromHostname = function(hostname) {
363363
// the list of hostnames by making it reusable (junkyard etc.) and which
364364
// has its own element counter property in order to avoid memory
365365
// alloc/dealloc.
366-
var nodes = [];
366+
var pos = hostname.indexOf('.');
367+
if ( pos < 0 ) {
368+
return [];
369+
}
370+
hostname = hostname.slice(pos + 1);
367371
var domain = this.domainFromHostname(hostname);
368-
if ( domain && domain !== hostname ) {
369-
var pos;
370-
while ( true ) {
371-
pos = hostname.indexOf('.');
372-
if ( pos < 0 ) {
373-
break;
374-
}
375-
hostname = hostname.slice(pos + 1);
376-
nodes.push(hostname);
377-
if ( hostname === domain ) {
378-
break;
379-
}
372+
if ( domain === '' ) {
373+
return [];
374+
}
375+
var nodes = [hostname];
376+
while ( hostname !== domain ) {
377+
pos = hostname.indexOf('.');
378+
if ( pos < 0 ) {
379+
break;
380380
}
381+
hostname = hostname.slice(pos + 1);
382+
nodes.push(hostname);
381383
}
382384
return nodes;
383385
};

0 commit comments

Comments
 (0)