From f6f7a78d89981d85cd9f4da41f9d715b106fa04f Mon Sep 17 00:00:00 2001 From: Andy Hanson Date: Wed, 7 Sep 2016 09:29:38 -0700 Subject: [PATCH] Optimize 'getSourceFile' to only get the source file once. --- src/services/services.ts | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/services/services.ts b/src/services/services.ts index eaba4779a52..778687557b2 100644 --- a/src/services/services.ts +++ b/src/services/services.ts @@ -127,7 +127,10 @@ namespace ts { } public getText(sourceFile?: SourceFile): string { - return (sourceFile || this.getSourceFile()).text.substring(this.getStart(), this.getEnd()); + if (!sourceFile) { + sourceFile = this.getSourceFile(); + } + return sourceFile.text.substring(this.getStart(sourceFile), this.getEnd()); } private addSyntheticNodes(nodes: Node[], pos: number, end: number, useJSDocScanner?: boolean): number { @@ -192,8 +195,8 @@ namespace ts { } } // For syntactic classifications, all trivia are classcified together, including jsdoc comments. - // For that to work, the jsdoc comments should still be the leading trivia of the first child. - // Restoring the scanner position ensures that. + // For that to work, the jsdoc comments should still be the leading trivia of the first child. + // Restoring the scanner position ensures that. pos = this.pos; forEachChild(this, processNode, processNodes); if (pos < this.end) {