Skip to content

Commit 9e6cacb

Browse files
committed
Merge branch 'master' into bom
2 parents 3295cda + 702b27b commit 9e6cacb

File tree

4 files changed

+47
-22
lines changed

4 files changed

+47
-22
lines changed

src/compiler/core.ts

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,31 @@ module ts {
152152

153153
export function mapToArray<T>(map: Map<T>): T[] {
154154
var result: T[] = [];
155-
for (var id in map) result.push(map[id]);
155+
156+
for (var id in map) {
157+
result.push(map[id]);
158+
}
159+
160+
return result;
161+
}
162+
163+
/**
164+
* Creates a map from the elements of an array.
165+
*
166+
* @param array the array of input elements.
167+
* @param makeKey a function that produces a key for a given element.
168+
*
169+
* This function makes no effort to avoid collisions; if any two elements produce
170+
* the same key with the given 'makeKey' function, then the element with the higher
171+
* index in the array will be the one associated with the produced key.
172+
*/
173+
export function arrayToMap<T>(array: T[], makeKey: (value: T) => string): Map<T> {
174+
var result: Map<T> = {};
175+
176+
forEach(array, value => {
177+
result[makeKey(value)] = value
178+
});
179+
156180
return result;
157181
}
158182

src/compiler/tc.ts

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -245,14 +245,14 @@ module ts {
245245

246246
function addWatchers(program: Program) {
247247
forEach(program.getSourceFiles(), f => {
248-
var filename = f.filename;
248+
var filename = getCanonicalName(f.filename);
249249
watchers[filename] = sys.watchFile(filename, fileUpdated);
250250
});
251251
}
252252

253253
function removeWatchers(program: Program) {
254254
forEach(program.getSourceFiles(), f => {
255-
var filename = f.filename;
255+
var filename = getCanonicalName(f.filename);
256256
if (hasProperty(watchers, filename)) {
257257
watchers[filename].close();
258258
}
@@ -264,8 +264,7 @@ module ts {
264264
// Fired off whenever a file is changed.
265265
function fileUpdated(filename: string) {
266266
var firstNotification = isEmpty(updatedFiles);
267-
268-
updatedFiles[filename] = true;
267+
updatedFiles[getCanonicalName(filename)] = true;
269268

270269
// Only start this off when the first file change comes in,
271270
// so that we can batch up all further changes.
@@ -285,20 +284,22 @@ module ts {
285284
// specified since the last compilation cycle.
286285
removeWatchers(program);
287286

288-
// Gets us syntactically correct files from the last compilation.
289-
var getUnmodifiedSourceFile = program.getSourceFile;
287+
// Reuse source files from the last compilation so long as they weren't changed.
288+
var oldSourceFiles = arrayToMap(
289+
filter(program.getSourceFiles(), file => !hasProperty(changedFiles, getCanonicalName(file.filename))),
290+
file => getCanonicalName(file.filename));
290291

291292
// We create a new compiler host for this compilation cycle.
292293
// This new host is effectively the same except that 'getSourceFile'
293294
// will try to reuse the SourceFiles from the last compilation cycle
294295
// so long as they were not modified.
295296
var newCompilerHost = clone(compilerHost);
296297
newCompilerHost.getSourceFile = (fileName, languageVersion, onError) => {
297-
if (!hasProperty(changedFiles, fileName)) {
298-
var sourceFile = getUnmodifiedSourceFile(fileName);
299-
if (sourceFile) {
300-
return sourceFile;
301-
}
298+
fileName = getCanonicalName(fileName);
299+
300+
var sourceFile = lookUp(oldSourceFiles, fileName);
301+
if (sourceFile) {
302+
return sourceFile;
302303
}
303304

304305
return compilerHost.getSourceFile(fileName, languageVersion, onError);
@@ -308,6 +309,10 @@ module ts {
308309
reportDiagnostic(createCompilerDiagnostic(Diagnostics.Compilation_complete_Watching_for_file_changes));
309310
addWatchers(program);
310311
}
312+
313+
function getCanonicalName(fileName: string) {
314+
return compilerHost.getCanonicalFileName(fileName);
315+
}
311316
}
312317

313318
function compile(commandLine: ParsedCommandLine, compilerHost: CompilerHost) {

tests/perfsys.ts

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,26 +8,24 @@ module perftest {
88

99
export interface IO {
1010
getOut(): string;
11-
getErr(): string;
1211
}
1312

1413
export var readFile = sys.readFile;
1514
var writeFile = sys.writeFile;
1615
export var write = sys.write;
17-
export var writeErr = sys.writeErr;
1816
var resolvePath = sys.resolvePath;
1917
export var getExecutingFilePath = sys.getExecutingFilePath;
2018
export var getCurrentDirectory = sys.getCurrentDirectory;
2119

2220
var args = sys.args;
2321

2422
// augment sys so first ts.executeCommandLine call will be finish silently
25-
sys.writeErr = (s: string) => { };
23+
sys.write = (s: string) => { };
2624
sys.args = []
2725

2826
export function restoreSys() {
2927
sys.args = args;
30-
sys.writeErr = writeErr;
28+
sys.write = write;
3129
}
3230

3331
export function hasLogIOFlag() {
@@ -96,11 +94,9 @@ module perftest {
9694
var err: string = "";
9795

9896
sys.write = (s: string) => { out += s; };
99-
sys.writeErr = (s: string) => { err += s; };
10097

10198
return {
10299
getOut: () => out,
103-
getErr: () => err
104100
};
105101
}
106102
}

tests/perftc.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,14 @@ if (perftest.hasLogIOFlag()) {
88
var compilerHost: ts.CompilerHost = {
99
getSourceFile: (s, v) => {
1010
var content = perftest.readFile(s);
11-
return content !== undefined ? ts.createSourceFile(s, content, v) : undefined;
11+
return content !== undefined ? ts.createSourceFile(s, content, v, ts.ByteOrderMark.Utf8) : undefined;
1212
},
1313
getDefaultLibFilename: () => ts.combinePaths(ts.getDirectoryPath(ts.normalizePath(perftest.getExecutingFilePath())), "lib.d.ts"),
1414
writeFile: (f: string, content: string) => { throw new Error("Unexpected operation: writeFile"); },
1515
getCurrentDirectory: () => perftest.getCurrentDirectory(),
16-
getCanonicalFileName: getCanonicalFileName,
17-
useCaseSensitiveFileNames: () => sys.useCaseSensitiveFileNames
16+
getCanonicalFileName: ts.getCanonicalFileName,
17+
useCaseSensitiveFileNames: () => sys.useCaseSensitiveFileNames,
18+
getNewLine: () => sys.newLine
1819
};
1920

2021
var commandLine = ts.parseCommandLine(perftest.getArgsWithoutLogIOFlag());
@@ -26,5 +27,4 @@ else {
2627
var io = perftest.prepare();
2728
ts.executeCommandLine(perftest.getArgsWithoutIOLogFile());
2829
perftest.write(io.getOut());
29-
perftest.writeErr(io.getErr());
3030
}

0 commit comments

Comments
 (0)