Skip to content

Commit 5b7aa98

Browse files
committed
Merge branch 'master' of github.com:microsoft/vscode
2 parents 33aaaa0 + 3f0e5b4 commit 5b7aa98

38 files changed

Lines changed: 169 additions & 200 deletions

File tree

src/vs/base/common/arrays.ts

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -472,17 +472,6 @@ export function range(arg: number, to?: number): number[] {
472472
return result;
473473
}
474474

475-
/**
476-
* @deprecated ES6: use `Array.fill`
477-
*/
478-
export function fill<T>(num: number, value: T, arr: T[] = []): T[] {
479-
for (let i = 0; i < num; i++) {
480-
arr[i] = value;
481-
}
482-
483-
return arr;
484-
}
485-
486475
export function index<T>(array: ReadonlyArray<T>, indexer: (t: T) => string): { [key: string]: T; };
487476
export function index<T, R>(array: ReadonlyArray<T>, indexer: (t: T) => string, merger?: (t: T, r: R) => R): { [key: string]: R; };
488477
export function index<T, R>(array: ReadonlyArray<T>, indexer: (t: T) => string, merger: (t: T, r: R) => R = t => t as any): { [key: string]: R; } {

src/vs/base/common/comparers.ts

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
* Licensed under the MIT License. See License.txt in the project root for license information.
44
*--------------------------------------------------------------------------------------------*/
55

6-
import * as strings from 'vs/base/common/strings';
76
import { sep } from 'vs/base/common/path';
87
import { IdleValue } from 'vs/base/common/async';
98

@@ -133,8 +132,8 @@ export function compareAnything(one: string, other: string, lookFor: string): nu
133132
}
134133

135134
// Sort suffix matches over non suffix matches
136-
const elementASuffixMatch = strings.endsWith(elementAName, lookFor);
137-
const elementBSuffixMatch = strings.endsWith(elementBName, lookFor);
135+
const elementASuffixMatch = elementAName.endsWith(lookFor);
136+
const elementBSuffixMatch = elementBName.endsWith(lookFor);
138137
if (elementASuffixMatch !== elementBSuffixMatch) {
139138
return elementASuffixMatch ? -1 : 1;
140139
}
@@ -154,8 +153,8 @@ export function compareByPrefix(one: string, other: string, lookFor: string): nu
154153
const elementBName = other.toLowerCase();
155154

156155
// Sort prefix matches over non prefix matches
157-
const elementAPrefixMatch = strings.startsWith(elementAName, lookFor);
158-
const elementBPrefixMatch = strings.startsWith(elementBName, lookFor);
156+
const elementAPrefixMatch = elementAName.startsWith(lookFor);
157+
const elementBPrefixMatch = elementBName.startsWith(lookFor);
159158
if (elementAPrefixMatch !== elementBPrefixMatch) {
160159
return elementAPrefixMatch ? -1 : 1;
161160
}

src/vs/base/common/extpath.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
*--------------------------------------------------------------------------------------------*/
55

66
import { isWindows } from 'vs/base/common/platform';
7-
import { startsWithIgnoreCase, equalsIgnoreCase, endsWith, rtrim } from 'vs/base/common/strings';
7+
import { startsWithIgnoreCase, equalsIgnoreCase, rtrim } from 'vs/base/common/strings';
88
import { CharCode } from 'vs/base/common/charCode';
99
import { sep, posix, isAbsolute, join, normalize } from 'vs/base/common/path';
1010

@@ -235,7 +235,7 @@ export function isWindowsDriveLetter(char0: number): boolean {
235235
export function sanitizeFilePath(candidate: string, cwd: string): string {
236236

237237
// Special case: allow to open a drive letter without trailing backslash
238-
if (isWindows && endsWith(candidate, ':')) {
238+
if (isWindows && candidate.endsWith(':')) {
239239
candidate += sep;
240240
}
241241

@@ -252,7 +252,7 @@ export function sanitizeFilePath(candidate: string, cwd: string): string {
252252
candidate = rtrim(candidate, sep);
253253

254254
// Special case: allow to open drive root ('C:\')
255-
if (endsWith(candidate, ':')) {
255+
if (candidate.endsWith(':')) {
256256
candidate += sep;
257257
}
258258

src/vs/base/common/glob.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -302,7 +302,7 @@ function parsePattern(arg1: string | IRelativePattern, options: IGlobOptions): P
302302
if (T1.test(pattern)) { // common pattern: **/*.txt just need endsWith check
303303
const base = pattern.substr(4); // '**/*'.length === 4
304304
parsedPattern = function (path, basename) {
305-
return typeof path === 'string' && strings.endsWith(path, base) ? pattern : null;
305+
return typeof path === 'string' && path.endsWith(base) ? pattern : null;
306306
};
307307
} else if (match = T2.exec(trimForExclusions(pattern, options))) { // common pattern: **/some.txt just need basename check
308308
parsedPattern = trivia2(match[1], pattern);
@@ -339,7 +339,7 @@ function wrapRelativePattern(parsedPattern: ParsedStringPattern, arg2: string |
339339
}
340340

341341
function trimForExclusions(pattern: string, options: IGlobOptions): string {
342-
return options.trimForExclusions && strings.endsWith(pattern, '/**') ? pattern.substr(0, pattern.length - 2) : pattern; // dropping **, tailing / is dropped later
342+
return options.trimForExclusions && pattern.endsWith('/**') ? pattern.substr(0, pattern.length - 2) : pattern; // dropping **, tailing / is dropped later
343343
}
344344

345345
// common pattern: **/some.txt just need basename check
@@ -353,7 +353,7 @@ function trivia2(base: string, originalPattern: string): ParsedStringPattern {
353353
if (basename) {
354354
return basename === base ? originalPattern : null;
355355
}
356-
return path === base || strings.endsWith(path, slashBase) || strings.endsWith(path, backslashBase) ? originalPattern : null;
356+
return path === base || path.endsWith(slashBase) || path.endsWith(backslashBase) ? originalPattern : null;
357357
};
358358
const basenames = [base];
359359
parsedPattern.basenames = basenames;
@@ -398,7 +398,7 @@ function trivia4and5(path: string, pattern: string, matchPathEnds: boolean): Par
398398
const nativePath = paths.sep !== paths.posix.sep ? path.replace(ALL_FORWARD_SLASHES, paths.sep) : path;
399399
const nativePathEnd = paths.sep + nativePath;
400400
const parsedPattern: ParsedStringPattern = matchPathEnds ? function (path, basename) {
401-
return typeof path === 'string' && (path === nativePath || strings.endsWith(path, nativePathEnd)) ? pattern : null;
401+
return typeof path === 'string' && (path === nativePath || path.endsWith(nativePathEnd)) ? pattern : null;
402402
} : function (path, basename) {
403403
return typeof path === 'string' && path === nativePath ? pattern : null;
404404
};

src/vs/base/common/labels.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
import { URI } from 'vs/base/common/uri';
77
import { posix, normalize, win32, sep } from 'vs/base/common/path';
8-
import { endsWith, startsWithIgnoreCase, rtrim, startsWith } from 'vs/base/common/strings';
8+
import { startsWithIgnoreCase, rtrim } from 'vs/base/common/strings';
99
import { Schemas } from 'vs/base/common/network';
1010
import { isLinux, isWindows, isMacintosh } from 'vs/base/common/platform';
1111
import { isEqual, basename, relativePath } from 'vs/base/common/resources';
@@ -117,7 +117,7 @@ export function tildify(path: string, userHome: string): string {
117117
}
118118

119119
// Linux: case sensitive, macOS: case insensitive
120-
if (isLinux ? startsWith(path, normalizedUserHome) : startsWithIgnoreCase(path, normalizedUserHome)) {
120+
if (isLinux ? path.startsWith(normalizedUserHome) : startsWithIgnoreCase(path, normalizedUserHome)) {
121121
path = `~/${path.substr(normalizedUserHome.length)}`;
122122
}
123123

@@ -210,7 +210,7 @@ export function shorten(paths: string[], pathSeparator: string = sep): string[]
210210
// Adding separator as prefix for subpath, such that 'endsWith(src, trgt)' considers subpath as directory name instead of plain string.
211211
// prefix is not added when either subpath is root directory or path[otherPathIndex] does not have multiple directories.
212212
const subpathWithSep: string = (start > 0 && paths[otherPathIndex].indexOf(pathSeparator) > -1) ? pathSeparator + subpath : subpath;
213-
const isOtherPathEnding: boolean = endsWith(paths[otherPathIndex], subpathWithSep);
213+
const isOtherPathEnding: boolean = paths[otherPathIndex].endsWith(subpathWithSep);
214214

215215
match = !isSubpathEnding || isOtherPathEnding;
216216
}
@@ -221,7 +221,7 @@ export function shorten(paths: string[], pathSeparator: string = sep): string[]
221221
let result = '';
222222

223223
// preserve disk drive or root prefix
224-
if (endsWith(segments[0], ':') || prefix !== '') {
224+
if (segments[0].endsWith(':') || prefix !== '') {
225225
if (start === 1) {
226226
// extend subpath to include disk drive prefix
227227
start = 0;

src/vs/base/common/map.ts

Lines changed: 0 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -56,32 +56,6 @@ export function setToString<K>(set: Set<K>): string {
5656
return `Set(${set.size}) {${entries.join(', ')}}`;
5757
}
5858

59-
/**
60-
* @deprecated ES6: use `...Map.entries()`
61-
*/
62-
export function mapToSerializable(map: Map<string, string>): [string, string][] {
63-
const serializable: [string, string][] = [];
64-
65-
map.forEach((value, key) => {
66-
serializable.push([key, value]);
67-
});
68-
69-
return serializable;
70-
}
71-
72-
/**
73-
* @deprecated ES6: use `new Map([[key1, value1],[key2, value2]])`
74-
*/
75-
export function serializableToMap(serializable: [string, string][]): Map<string, string> {
76-
const items = new Map<string, string>();
77-
78-
for (const [key, value] of serializable) {
79-
items.set(key, value);
80-
}
81-
82-
return items;
83-
}
84-
8559
export interface IKeyIterator {
8660
reset(key: string): this;
8761
next(): this;

src/vs/base/common/mime.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
*--------------------------------------------------------------------------------------------*/
55

66
import { basename, posix, extname } from 'vs/base/common/path';
7-
import { endsWith, startsWithUTF8BOM, startsWith } from 'vs/base/common/strings';
7+
import { startsWithUTF8BOM } from 'vs/base/common/strings';
88
import { coalesce } from 'vs/base/common/arrays';
99
import { match } from 'vs/base/common/glob';
1010
import { URI } from 'vs/base/common/uri';
@@ -185,7 +185,7 @@ function guessMimeTypeByPath(path: string, filename: string, associations: IText
185185
// Longest extension match
186186
if (association.extension) {
187187
if (!extensionMatch || association.extension.length > extensionMatch.extension!.length) {
188-
if (endsWith(filename, association.extensionLowercase!)) {
188+
if (filename.endsWith(association.extensionLowercase!)) {
189189
extensionMatch = association;
190190
}
191191
}
@@ -259,11 +259,11 @@ export function suggestFilename(mode: string | undefined, prefix: string): strin
259259
.map(assoc => assoc.extension);
260260

261261
const extensionsWithDotFirst = coalesce(extensions)
262-
.filter(assoc => startsWith(assoc, '.'));
262+
.filter(assoc => assoc.startsWith('.'));
263263

264264
if (extensionsWithDotFirst.length > 0) {
265265
const candidateExtension = extensionsWithDotFirst[0];
266-
if (endsWith(prefix, candidateExtension)) {
266+
if (prefix.endsWith(candidateExtension)) {
267267
// do not add the prefix if it already exists
268268
// https://github.com/microsoft/vscode/issues/83603
269269
return prefix;

src/vs/base/node/pfs.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ import * as fs from 'fs';
99
import * as os from 'os';
1010
import * as platform from 'vs/base/common/platform';
1111
import { Event } from 'vs/base/common/event';
12-
import { endsWith } from 'vs/base/common/strings';
1312
import { promisify } from 'util';
1413
import { isRootOrDriveLetter } from 'vs/base/common/extpath';
1514
import { generateUuid } from 'vs/base/common/uuid';
@@ -492,7 +491,7 @@ export async function move(source: string, target: string): Promise<void> {
492491
//
493492
// 2.) The user tries to rename a file/folder that ends with a dot. This is not
494493
// really possible to move then, at least on UNC devices.
495-
if (source.toLowerCase() !== target.toLowerCase() && error.code === 'EXDEV' || endsWith(source, '.')) {
494+
if (source.toLowerCase() !== target.toLowerCase() && error.code === 'EXDEV' || source.endsWith('.')) {
496495
await copy(source, target);
497496
await rimraf(source, RimRafMode.MOVE);
498497
await updateMtime(target);

src/vs/base/parts/storage/node/storage.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ import { timeout } from 'vs/base/common/async';
99
import { mapToString, setToString } from 'vs/base/common/map';
1010
import { basename } from 'vs/base/common/path';
1111
import { copy, renameIgnoreError, unlink } from 'vs/base/node/pfs';
12-
import { fill } from 'vs/base/common/arrays';
1312
import { IStorageDatabase, IStorageItemsChangeEvent, IUpdateRequest } from 'vs/base/parts/storage/common/storage';
1413

1514
interface IDatabaseConnection {
@@ -97,7 +96,7 @@ export class SQLiteStorageDatabase implements IStorageDatabase {
9796
});
9897

9998
keysValuesChunks.forEach(keysValuesChunk => {
100-
this.prepare(connection, `INSERT INTO ItemTable VALUES ${fill(keysValuesChunk.length / 2, '(?,?)').join(',')}`, stmt => stmt.run(keysValuesChunk), () => {
99+
this.prepare(connection, `INSERT INTO ItemTable VALUES ${new Array(keysValuesChunk.length / 2).fill('(?,?)').join(',')}`, stmt => stmt.run(keysValuesChunk), () => {
101100
const keys: string[] = [];
102101
let length = 0;
103102
toInsert.forEach((value, key) => {
@@ -132,7 +131,7 @@ export class SQLiteStorageDatabase implements IStorageDatabase {
132131
});
133132

134133
keysChunks.forEach(keysChunk => {
135-
this.prepare(connection, `DELETE FROM ItemTable WHERE key IN (${fill(keysChunk.length, '?').join(',')})`, stmt => stmt.run(keysChunk), () => {
134+
this.prepare(connection, `DELETE FROM ItemTable WHERE key IN (${new Array(keysChunk.length).fill('?').join(',')})`, stmt => stmt.run(keysChunk), () => {
136135
const keys: string[] = [];
137136
toDelete.forEach(key => {
138137
keys.push(key);

src/vs/base/test/common/map.test.ts

Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
* Licensed under the MIT License. See License.txt in the project root for license information.
44
*--------------------------------------------------------------------------------------------*/
55

6-
import { ResourceMap, TernarySearchTree, PathIterator, StringIterator, LinkedMap, Touch, LRUCache, mapToSerializable, serializableToMap } from 'vs/base/common/map';
6+
import { ResourceMap, TernarySearchTree, PathIterator, StringIterator, LinkedMap, Touch, LRUCache } from 'vs/base/common/map';
77
import * as assert from 'assert';
88
import { URI } from 'vs/base/common/uri';
99

@@ -629,17 +629,4 @@ suite('Map', () => {
629629
// assert.equal(map.get(windowsFile), 'true');
630630
// assert.equal(map.get(uncFile), 'true');
631631
// });
632-
633-
test('mapToSerializable / serializableToMap', function () {
634-
const map = new Map<string, string>();
635-
map.set('1', 'foo');
636-
map.set('2', null!);
637-
map.set('3', 'bar');
638-
639-
const map2 = serializableToMap(mapToSerializable(map));
640-
assert.equal(map2.size, map.size);
641-
assert.equal(map2.get('1'), map.get('1'));
642-
assert.equal(map2.get('2'), map.get('2'));
643-
assert.equal(map2.get('3'), map.get('3'));
644-
});
645632
});

0 commit comments

Comments
 (0)