Skip to content
This repository was archived by the owner on Apr 12, 2024. It is now read-only.

Commit 1e1c8c8

Browse files
committed
minor speed improvements or URL parsing
1 parent cdda664 commit 1e1c8c8

File tree

1 file changed

+18
-17
lines changed

1 file changed

+18
-17
lines changed

src/services.js

Lines changed: 18 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ angularService("$location", function(browser){
2424
if (href) {
2525
parseUrl(href);
2626
} else {
27-
href = check('href') || check('protocol', '://', 'host', ':', 'port', '', 'path', '?', 'search');
27+
href = check('href') || checkProtocol();
2828
var hash = check('hash');
2929
if (isUndefined(hash)) hash = checkHashPathSearch();
3030
if (isDefined(hash)) {
@@ -38,19 +38,22 @@ angularService("$location", function(browser){
3838
}
3939
}
4040

41-
function check() {
42-
var i = -1,
43-
length=arguments.length,
44-
name, seperator, parts = [],
45-
value, same = true;
46-
for(; i<length; i = i+2) {
47-
parts.push(seperator = (arguments[i] || ''));
48-
name = arguments[i + 1];
49-
value=location[name];
50-
parts.push(typeof value == 'object' ? toKeyValue(value) : value);
51-
same = same && equals(lastLocation[name], value);
52-
}
53-
return same ? undefined : parts.join('');
41+
function check(param) {
42+
return lastLocation[param] == location[param] ? undefined : location[param];
43+
}
44+
45+
function checkProtocol(){
46+
if (lastLocation.protocol === location.protocol &&
47+
lastLocation.host === location.host &&
48+
lastLocation.port === location.port &&
49+
lastLocation.path === location.path &&
50+
equals(lastLocation.search, location.search))
51+
return undefined;
52+
var url = toKeyValue(location.search);
53+
var port = (location.port == DEFAULT_PORTS[location.protocol] ? null : location.port);
54+
return location.protocol + '://' + location.host +
55+
(port ? ':' + port : '') + location.path +
56+
(url ? '?' + url : '');
5457
}
5558

5659
function checkHashPathSearch(){
@@ -71,9 +74,7 @@ angularService("$location", function(browser){
7174
location.port = match[5] || DEFAULT_PORTS[location.protocol] || null;
7275
location.path = match[6];
7376
location.search = parseKeyValue(match[8]);
74-
location.hash = match[9] || '';
75-
if (location.hash)
76-
location.hash = location.hash.substr(1);
77+
location.hash = match[10] || '';
7778
match = HASH_MATCH.exec(location.hash);
7879
location.hashPath = unescape(match[1] || '');
7980
location.hashSearch = parseKeyValue(match[3]);

0 commit comments

Comments
 (0)