From 01d022a430182a821c1b27720d5fcbf79b6422fd Mon Sep 17 00:00:00 2001 From: Johannes Rieken Date: Fri, 1 Jun 2018 12:42:18 +0200 Subject: [PATCH] use string-concat (with little improvement) #50800 --- src/vs/base/common/uri.ts | 38 ++++++++++++++++++++++++-------------- 1 file changed, 24 insertions(+), 14 deletions(-) diff --git a/src/vs/base/common/uri.ts b/src/vs/base/common/uri.ts index d2fdb47ea2a..19526969f17 100644 --- a/src/vs/base/common/uri.ts +++ b/src/vs/base/common/uri.ts @@ -411,34 +411,42 @@ function _asFormatted(uri: URI, skipEncoding: boolean): string { ? encodeURIComponent2 : encodeNoop; - const parts: string[] = []; + let res = ''; let { scheme, authority, path, query, fragment } = uri; if (scheme) { - parts.push(scheme, ':'); + res += scheme; + res += ':'; } if (authority || scheme === 'file') { - parts.push('//'); + res += _slash; + res += _slash; } if (authority) { let idx = authority.indexOf('@'); if (idx !== -1) { + // @ const userinfo = authority.substr(0, idx); authority = authority.substr(idx + 1); idx = userinfo.indexOf(':'); if (idx === -1) { - parts.push(encoder(userinfo)); + res += encoder(userinfo); } else { - parts.push(encoder(userinfo.substr(0, idx)), ':', encoder(userinfo.substr(idx + 1))); + // :@ + res += encoder(userinfo.substr(0, idx)); + res += ':'; + res += encoder(userinfo.substr(idx + 1)); } - parts.push('@'); + res += '@'; } authority = authority.toLowerCase(); idx = authority.indexOf(':'); if (idx === -1) { - parts.push(encoder(authority)); + res += encoder(authority); } else { - parts.push(encoder(authority.substr(0, idx)), authority.substr(idx)); + // : + res += encoder(authority.substr(0, idx)); + res += authority.substr(idx); } } if (path) { @@ -460,19 +468,21 @@ function _asFormatted(uri: URI, skipEncoding: boolean): string { while (true) { let idx = path.indexOf(_slash, lastIdx); if (idx === -1) { - parts.push(encoder(path.substring(lastIdx))); + res += encoder(path.substring(lastIdx)); break; } - parts.push(encoder(path.substring(lastIdx, idx)), _slash); + res += encoder(path.substring(lastIdx, idx)); + res += _slash; lastIdx = idx + 1; } } if (query) { - parts.push('?', encoder(query)); + res += '?'; + res += encoder(query); } if (fragment) { - parts.push('#', encoder(fragment)); + res += '#'; + res += encoder(fragment); } - - return parts.join(_empty); + return res; } -- GitLab