From 39254b54ae3b5b51517aa7a2217c5c852e8ceab2 Mon Sep 17 00:00:00 2001 From: zhengbli Date: Mon, 19 Oct 2015 21:48:40 -0700 Subject: [PATCH] CR feedback --- src/compiler/tsc.ts | 2 +- src/compiler/utilities.ts | 8 ++------ src/server/editorServices.ts | 2 +- 3 files changed, 4 insertions(+), 8 deletions(-) diff --git a/src/compiler/tsc.ts b/src/compiler/tsc.ts index b4774b9a842..e51fda074c5 100644 --- a/src/compiler/tsc.ts +++ b/src/compiler/tsc.ts @@ -361,7 +361,7 @@ namespace ts { let canonicalRootFileNames = ts.map(rootFileNames, compilerHost.getCanonicalFileName); // We check if the project file list has changed. If so, we just throw away the old program and start fresh. - if (!arrayIsEqualTo(newFileNames, canonicalRootFileNames, /*equaler*/ undefined, /*sortBeforeComparison*/ true)) { + if (!arrayIsEqualTo(newFileNames && newFileNames.sort(), canonicalRootFileNames && canonicalRootFileNames.sort())) { setCachedProgram(undefined); startTimerForRecompilation(); } diff --git a/src/compiler/utilities.ts b/src/compiler/utilities.ts index b56c63013aa..7c1b606dd00 100644 --- a/src/compiler/utilities.ts +++ b/src/compiler/utilities.ts @@ -82,8 +82,7 @@ namespace ts { return node.end - node.pos; } - export function arrayIsEqualTo(array1: T[], array2: T[], equaler?: (a: T, b: T) => boolean, - sortBeforeComparison?: boolean, comparer?: (a: T, b: T) => number): boolean { + export function arrayIsEqualTo(array1: T[], array2: T[], equaler?: (a: T, b: T) => boolean): boolean { if (!array1 || !array2) { return array1 === array2; } @@ -92,11 +91,8 @@ namespace ts { return false; } - let newArray1 = sortBeforeComparison ? array1.slice().sort(comparer) : array1; - let newArray2 = sortBeforeComparison ? array2.slice().sort(comparer) : array2; - for (let i = 0; i < array1.length; ++i) { - let equals = equaler ? equaler(newArray1[i], newArray2[i]) : newArray1[i] === newArray2[i]; + let equals = equaler ? equaler(array1[i], array2[i]) : array1[i] === array2[i]; if (!equals) { return false; } diff --git a/src/server/editorServices.ts b/src/server/editorServices.ts index 7cb047bb74d..efcca0e37c5 100644 --- a/src/server/editorServices.ts +++ b/src/server/editorServices.ts @@ -577,7 +577,7 @@ namespace ts.server { let currentRootFiles = project.getRootFiles().map((f => this.getCanonicalFileName(f))); // We check if the project file list has changed. If so, we update the project. - if (!arrayIsEqualTo(currentRootFiles, newRootFiles, /*equaler*/ undefined, /*sortBeforeComparison*/ true)) { + if (!arrayIsEqualTo(currentRootFiles && currentRootFiles.sort(), newRootFiles && newRootFiles.sort())) { // For configured projects, the change is made outside the tsconfig file, and // it is not likely to affect the project for other files opened by the client. We can // just update the current project.