Skip to content

Commit f6f7a78

Browse files
author
Andy Hanson
committed
Optimize 'getSourceFile' to only get the source file once.
1 parent 4685646 commit f6f7a78

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

src/services/services.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,10 @@ namespace ts {
127127
}
128128

129129
public getText(sourceFile?: SourceFile): string {
130-
return (sourceFile || this.getSourceFile()).text.substring(this.getStart(), this.getEnd());
130+
if (!sourceFile) {
131+
sourceFile = this.getSourceFile();
132+
}
133+
return sourceFile.text.substring(this.getStart(sourceFile), this.getEnd());
131134
}
132135

133136
private addSyntheticNodes(nodes: Node[], pos: number, end: number, useJSDocScanner?: boolean): number {
@@ -192,8 +195,8 @@ namespace ts {
192195
}
193196
}
194197
// For syntactic classifications, all trivia are classcified together, including jsdoc comments.
195-
// For that to work, the jsdoc comments should still be the leading trivia of the first child.
196-
// Restoring the scanner position ensures that.
198+
// For that to work, the jsdoc comments should still be the leading trivia of the first child.
199+
// Restoring the scanner position ensures that.
197200
pos = this.pos;
198201
forEachChild(this, processNode, processNodes);
199202
if (pos < this.end) {

0 commit comments

Comments
 (0)