From 8e292a19f7d451c6b03ab636434d7f70831b76e8 Mon Sep 17 00:00:00 2001 From: Cyrus Najmabadi Date: Wed, 25 Feb 2015 13:39:57 -0800 Subject: [PATCH] Avoid allocation during binary expression emit when unnecessary. --- src/compiler/emitter.ts | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/src/compiler/emitter.ts b/src/compiler/emitter.ts index 3247b5ff1d1..30d863ab90d 100644 --- a/src/compiler/emitter.ts +++ b/src/compiler/emitter.ts @@ -3109,13 +3109,12 @@ module ts { // // So we only indent if the right side of the binary expression starts further in on the line // versus the left. - var operatorEnd = getLineAndCharacterOfPosition(currentSourceFile, node.operatorToken.end); - var rightStart = getLineAndCharacterOfPosition(currentSourceFile, skipTrivia(currentSourceFile.text, node.right.pos)); // Check if the right expression is on a different line versus the operator itself. If so, // we'll emit newline. - var onDifferentLine = operatorEnd.line !== rightStart.line; - if (onDifferentLine) { + if (!nodeEndIsOnSameLineAsNodeStart(node.operatorToken, node.right)) { + var rightStart = getLineAndCharacterOfPosition(currentSourceFile, skipTrivia(currentSourceFile.text, node.right.pos)); + // Also, if the right expression starts further in on the line than the left, then we'll indent. var exprStart = getLineAndCharacterOfPosition(currentSourceFile, skipTrivia(currentSourceFile.text, node.pos)); var firstCharOfExpr = getFirstNonWhitespaceCharacterIndexOnLine(exprStart.line);