private TokenPairWithOperations[] CreateTokenOperation( TokenStream tokenStream, CancellationToken cancellationToken) { cancellationToken.ThrowIfCancellationRequested(); using (Logger.LogBlock(FunctionId.Formatting_CollectTokenOperation, cancellationToken)) { // pre-allocate list once. this is cheaper than re-adjusting list as items are added. var list = new TokenPairWithOperations[tokenStream.TokenCount - 1]; foreach (var pair in tokenStream.TokenIterator) { cancellationToken.ThrowIfCancellationRequested(); var spaceOperation = _formattingRules.GetAdjustSpacesOperation(pair.Item2, pair.Item3); var lineOperation = _formattingRules.GetAdjustNewLinesOperation(pair.Item2, pair.Item3); list[pair.Item1] = new TokenPairWithOperations(tokenStream, pair.Item1, spaceOperation, lineOperation); } return(list); } }
private SegmentedArray <TokenPairWithOperations> CreateTokenOperation( TokenStream tokenStream, CancellationToken cancellationToken) { cancellationToken.ThrowIfCancellationRequested(); using (Logger.LogBlock(FunctionId.Formatting_CollectTokenOperation, cancellationToken)) { // pre-allocate list once. this is cheaper than re-adjusting list as items are added. var list = new SegmentedArray <TokenPairWithOperations>(tokenStream.TokenCount - 1); foreach (var(index, currentToken, nextToken) in tokenStream.TokenIterator) { cancellationToken.ThrowIfCancellationRequested(); var spaceOperation = _formattingRules.GetAdjustSpacesOperation(currentToken, nextToken); var lineOperation = _formattingRules.GetAdjustNewLinesOperation(currentToken, nextToken); list[index] = new TokenPairWithOperations(tokenStream, index, spaceOperation, lineOperation); } return(list); } }
private Task <TokenPairWithOperations[]> CreateTokenOperationTask( TokenStream tokenStream, CancellationToken cancellationToken) { return(this.TaskExecutor.StartNew(() => { using (Logger.LogBlock(FunctionId.Formatting_CollectTokenOperation, cancellationToken)) { // pre-allocate list once. this is cheaper than re-adjusting list as items are added. var list = new TokenPairWithOperations[tokenStream.TokenCount - 1]; this.TaskExecutor.ForEach(tokenStream.TokenIterator, pair => { var spaceOperation = _formattingRules.GetAdjustSpacesOperation(pair.Item2, pair.Item3); var lineOperation = _formattingRules.GetAdjustNewLinesOperation(pair.Item2, pair.Item3); list[pair.Item1] = new TokenPairWithOperations(tokenStream, pair.Item1, spaceOperation, lineOperation); }, cancellationToken); return list; } }, cancellationToken)); }