From: Eduardo San Martin Morote Date: Wed, 22 Apr 2020 20:17:47 +0000 (+0200) Subject: perf: use index access for strings X-Git-Tag: v4.0.0-alpha.8~50 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=971fea415fcce84ce86d8ace67b65115af3b7ac2;p=thirdparty%2Fvuejs%2Frouter.git perf: use index access for strings --- diff --git a/src/history/common.ts b/src/history/common.ts index dd594bb5..09420236 100644 --- a/src/history/common.ts +++ b/src/history/common.ts @@ -162,7 +162,7 @@ export function normalizeBase(base?: string): string { // ensure leading slash when it was removed by the regex above avoid leading // slash with hash because the file could be read from the disk like file:// // and the leading slash would cause problems - if (base.charAt(0) !== '/' && base.charAt(0) !== '#') base = '/' + base + if (base[0] !== '/' && base[0] !== '#') base = '/' + base // remove the trailing slash so all other method can just do `base + fullPath` // to build an href diff --git a/src/history/html5.ts b/src/history/html5.ts index 58878b56..6af8d757 100644 --- a/src/history/html5.ts +++ b/src/history/html5.ts @@ -39,7 +39,7 @@ function createCurrentLocation( if (hashPos > -1) { // prepend the starting slash to hash so the url starts with /# let pathFromHash = hash.slice(1) - if (pathFromHash.charAt(0) !== '/') pathFromHash = '/' + pathFromHash + if (pathFromHash[0] !== '/') pathFromHash = '/' + pathFromHash return normalizeHistoryLocation(stripBase(pathFromHash, '')) } const path = stripBase(pathname, base) diff --git a/src/utils/location.ts b/src/utils/location.ts index fb82350d..84f5f98a 100644 --- a/src/utils/location.ts +++ b/src/utils/location.ts @@ -95,7 +95,8 @@ export function stringifyURL( * @param base - base to strip off */ export function stripBase(pathname: string, base: string): string { - if (!base || pathname.indexOf(base) !== 0) return pathname + // no base or base is not found at the begining + if (!base || pathname.indexOf(base)) return pathname return pathname.replace(base, '') || '/' }