diff options
| author | Misko Hevery | 2010-07-30 11:45:52 -0700 | 
|---|---|---|
| committer | Misko Hevery | 2010-07-30 11:45:52 -0700 | 
| commit | 1e1c8c82f98f4a6d6ed77e7bf34ac5177fe33d4f (patch) | |
| tree | 9c506519acdb8def17da5882b09b5d31e6a1753b /src/services.js | |
| parent | cdda664f8990351453baa26fc3dcd53329e72e68 (diff) | |
| download | angular.js-1e1c8c82f98f4a6d6ed77e7bf34ac5177fe33d4f.tar.bz2 | |
minor speed improvements or URL parsing
Diffstat (limited to 'src/services.js')
| -rw-r--r-- | src/services.js | 35 | 
1 files changed, 18 insertions, 17 deletions
diff --git a/src/services.js b/src/services.js index 6a52d25a..8df23564 100644 --- a/src/services.js +++ b/src/services.js @@ -24,7 +24,7 @@ angularService("$location", function(browser){      if (href) {        parseUrl(href);      } else { -      href = check('href') || check('protocol', '://', 'host', ':', 'port', '', 'path', '?', 'search'); +      href = check('href') || checkProtocol();        var hash = check('hash');        if (isUndefined(hash)) hash = checkHashPathSearch();        if (isDefined(hash)) { @@ -38,19 +38,22 @@ angularService("$location", function(browser){      }    } -  function check() { -    var i = -1, -        length=arguments.length, -        name, seperator, parts = [], -        value, same = true; -    for(; i<length; i = i+2) { -      parts.push(seperator = (arguments[i] || '')); -      name = arguments[i + 1]; -      value=location[name]; -      parts.push(typeof value == 'object' ? toKeyValue(value) : value); -      same = same && equals(lastLocation[name], value); -    } -    return same ? undefined : parts.join(''); +  function check(param) { +    return lastLocation[param] == location[param] ? undefined : location[param]; +  } + +  function checkProtocol(){ +    if (lastLocation.protocol === location.protocol && +        lastLocation.host === location.host && +        lastLocation.port === location.port && +        lastLocation.path === location.path && +        equals(lastLocation.search, location.search)) +      return undefined; +    var url = toKeyValue(location.search); +    var port = (location.port == DEFAULT_PORTS[location.protocol] ? null : location.port); +    return location.protocol  + '://' + location.host + +          (port ? ':' + port : '') + location.path + +          (url ? '?' + url : '');    }    function checkHashPathSearch(){ @@ -71,9 +74,7 @@ angularService("$location", function(browser){          location.port = match[5] || DEFAULT_PORTS[location.protocol] || null;          location.path = match[6];          location.search = parseKeyValue(match[8]); -        location.hash = match[9] || ''; -        if (location.hash) -          location.hash = location.hash.substr(1); +        location.hash = match[10] || '';          match = HASH_MATCH.exec(location.hash);          location.hashPath = unescape(match[1] || '');          location.hashSearch = parseKeyValue(match[3]);  | 
