From 45c3dffd4e257b3e3191072374bea71e831726a9 Mon Sep 17 00:00:00 2001 From: Cyrus Najmabadi Date: Fri, 21 Nov 2014 14:39:06 -0800 Subject: [PATCH] Slightly speed up marking by avoiding calling fullStart on so many nodes and tokens. --- src/services/syntax/incrementalParser.ts | 43 +++++++++++++----------- 1 file changed, 23 insertions(+), 20 deletions(-) diff --git a/src/services/syntax/incrementalParser.ts b/src/services/syntax/incrementalParser.ts index b086b984926..8af373ce5da 100644 --- a/src/services/syntax/incrementalParser.ts +++ b/src/services/syntax/incrementalParser.ts @@ -75,7 +75,7 @@ module TypeScript.IncrementalParser { // Also, mark any syntax elements that intersect the changed span. We know, up front, // that we cannot reuse these elements. updateTokenPositionsAndMarkElements(oldSourceUnit, - _changeRange.span().start(), _changeRange.span().end(), delta); + _changeRange.span().start(), _changeRange.span().end(), delta, /*fullStart:*/ 0); function release() { _scannerParserSource.release(); @@ -718,31 +718,34 @@ module TypeScript.IncrementalParser { } var tokenCollectorWalker = new TokenCollectorWalker(); - function updateTokenPositionsAndMarkElements(element: ISyntaxElementInternal, changeStart: number, changeRangeOldEnd: number, delta: number): void { - if (element) { + function updateTokenPositionsAndMarkElements(element: ISyntaxElementInternal, changeStart: number, changeRangeOldEnd: number, delta: number, fullStart: number): void { // First, try to skip past any elements that we dont' need to move. We don't need to // move any elements that don't start after the end of the change range. - if (fullStart(element) > changeRangeOldEnd) { - // Note, we only move elements that are truly after the end of the change range. - // We consider elements that are touching the end of the change range to be unusable. - forceUpdateTokenPositionsForElement(element, delta); - } - else { - // Check if the element intersects the change range. If it does, then it is not - // reusable. Also, we'll need to recurse to see what constituent portions we may - // be able to use. - if (fullEnd(element) >= changeStart) { - element.intersectsChange = true; + if (fullStart > changeRangeOldEnd) { + // Note, we only move elements that are truly after the end of the change range. + // We consider elements that are touching the end of the change range to be unusable. + forceUpdateTokenPositionsForElement(element, delta); + } + else { + // Check if the element intersects the change range. If it does, then it is not + // reusable. Also, we'll need to recurse to see what constituent portions we may + // be able to use. + var fullEnd = fullStart + fullWidth(element); + if (fullEnd >= changeStart) { + element.intersectsChange = true; - for (var i = 0, n = childCount(element); i < n; i++) { - updateTokenPositionsAndMarkElements(childAt(element, i), changeStart, changeRangeOldEnd, delta); + for (var i = 0, n = childCount(element); i < n; i++) { + var child = childAt(element, i); + if (child) { + updateTokenPositionsAndMarkElements(child, changeStart, changeRangeOldEnd, delta, fullStart); + fullStart += fullWidth(child); } } - // else { - // This element ended strictly before the edited range. We don't need to do anything - // with it. - // } } + // else { + // This element ended strictly before the edited range. We don't need to do anything + // with it. + // } } }