@@ -237,7 +237,7 @@ private static Doc PrivatePrintLeadingTrivia(
237
237
return Doc . Null ;
238
238
}
239
239
240
- var docs = new List < Doc > ( ) ;
240
+ var docs = new ValueListBuilder < Doc > ( [ null , null , null , null , null , null , null , null ] ) ;
241
241
242
242
// we don't print any new lines until we run into a comment or directive
243
243
// the PrintExtraNewLines method takes care of printing the initial new lines for a given node
@@ -250,28 +250,28 @@ private static Doc PrivatePrintLeadingTrivia(
250
250
251
251
if ( printNewLines && kind == SyntaxKind . EndOfLineTrivia )
252
252
{
253
- if ( docs . Count > 0 && docs [ ^ 1 ] == Doc . HardLineSkipBreakIfFirstInGroup )
253
+ if ( docs . Length > 0 && docs [ ^ 1 ] == Doc . HardLineSkipBreakIfFirstInGroup )
254
254
{
255
255
printNewLines = false ;
256
256
}
257
257
258
258
if (
259
259
! (
260
- docs . Count > 1
260
+ docs . Length > 1
261
261
&& docs [ ^ 1 ] == Doc . HardLineSkipBreakIfFirstInGroup
262
262
&& docs [ ^ 2 ] is LeadingComment { Type : CommentType . SingleLine }
263
263
)
264
264
)
265
265
{
266
- docs . Add ( Doc . HardLineSkipBreakIfFirstInGroup ) ;
266
+ docs . Append ( Doc . HardLineSkipBreakIfFirstInGroup ) ;
267
267
}
268
268
}
269
269
if ( kind is not ( SyntaxKind . EndOfLineTrivia or SyntaxKind . WhitespaceTrivia ) )
270
270
{
271
271
printNewLines = true ;
272
272
}
273
273
274
- void AddLeadingComment ( CommentType commentType )
274
+ void AddLeadingComment ( CommentType commentType , ref ValueListBuilder < Doc > docs )
275
275
{
276
276
var comment = trivia . ToFullString ( ) . TrimEnd ( '\n ' , '\r ' ) ;
277
277
if (
@@ -283,43 +283,43 @@ void AddLeadingComment(CommentType commentType)
283
283
comment = leadingTrivia [ x - 1 ] + comment ;
284
284
}
285
285
286
- docs . Add ( Doc . LeadingComment ( comment , commentType ) ) ;
286
+ docs . Append ( Doc . LeadingComment ( comment , commentType ) ) ;
287
287
}
288
288
289
289
if ( IsSingleLineComment ( kind ) )
290
290
{
291
- AddLeadingComment ( CommentType . SingleLine ) ;
292
- docs . Add (
291
+ AddLeadingComment ( CommentType . SingleLine , ref docs ) ;
292
+ docs . Append (
293
293
kind == SyntaxKind . SingleLineDocumentationCommentTrivia
294
294
? Doc . HardLineSkipBreakIfFirstInGroup
295
295
: Doc . Null
296
296
) ;
297
297
}
298
298
else if ( IsMultiLineComment ( kind ) )
299
299
{
300
- AddLeadingComment ( CommentType . MultiLine ) ;
300
+ AddLeadingComment ( CommentType . MultiLine , ref docs ) ;
301
301
}
302
302
else if ( kind == SyntaxKind . DisabledTextTrivia )
303
303
{
304
- docs . Add ( Doc . Trim , trivia . ToString ( ) ) ;
304
+ docs . Append ( Doc . Trim , trivia . ToString ( ) ) ;
305
305
}
306
306
else if ( IsRegion ( kind ) )
307
307
{
308
308
var triviaText = trivia . ToString ( ) ;
309
- docs . Add ( Doc . HardLineIfNoPreviousLine ) ;
310
- docs . Add ( Doc . Trim ) ;
311
- docs . Add (
309
+ docs . Append ( Doc . HardLineIfNoPreviousLine ) ;
310
+ docs . Append ( Doc . Trim ) ;
311
+ docs . Append (
312
312
kind == SyntaxKind . RegionDirectiveTrivia
313
313
? Doc . BeginRegion ( triviaText )
314
314
: Doc . EndRegion ( triviaText )
315
315
) ;
316
- docs . Add ( Doc . HardLine ) ;
316
+ docs . Append ( Doc . HardLine ) ;
317
317
}
318
318
else if ( trivia . IsDirective )
319
319
{
320
320
var triviaText = trivia . ToString ( ) ;
321
321
322
- docs . Add (
322
+ docs . Append (
323
323
// adding two of these to ensure we get a new line when a directive follows a trailing comment
324
324
Doc . HardLineIfNoPreviousLineSkipBreakIfFirstInGroup ,
325
325
Doc . HardLineIfNoPreviousLineSkipBreakIfFirstInGroup ,
@@ -337,16 +337,16 @@ void AddLeadingComment(CommentType commentType)
337
337
)
338
338
{
339
339
x ++ ;
340
- docs . Add ( Doc . HardLineSkipBreakIfFirstInGroup ) ;
340
+ docs . Append ( Doc . HardLineSkipBreakIfFirstInGroup ) ;
341
341
}
342
342
printNewLines = false ;
343
343
}
344
344
}
345
345
}
346
346
347
- while ( skipLastHardline && docs . Count != 0 && docs . Last ( ) is HardLine or NullDoc )
347
+ while ( skipLastHardline && docs . Length != 0 && docs [ ^ 1 ] is HardLine or NullDoc )
348
348
{
349
- docs . RemoveAt ( docs . Count - 1 ) ;
349
+ docs . Pop ( ) ;
350
350
}
351
351
352
352
if ( context . State . NextTriviaNeedsLine )
@@ -362,7 +362,7 @@ void AddLeadingComment(CommentType commentType)
362
362
}
363
363
else
364
364
{
365
- var index = docs . Count - 1 ;
365
+ var index = docs . Length - 1 ;
366
366
while (
367
367
index >= 0
368
368
&& ( docs [ index ] is HardLine or LeadingComment || docs [ index ] == Doc . Null )
@@ -373,7 +373,7 @@ void AddLeadingComment(CommentType commentType)
373
373
// this handles an edge case where we get here but already added the line
374
374
// it relates to the fact that single line comments include new line directives
375
375
if (
376
- index + 2 >= docs . Count
376
+ index + 2 >= docs . Length
377
377
|| ! ( docs [ index + 1 ] is HardLine && docs [ index + 2 ] is HardLine )
378
378
)
379
379
{
@@ -383,7 +383,7 @@ void AddLeadingComment(CommentType commentType)
383
383
context . State . NextTriviaNeedsLine = false ;
384
384
}
385
385
386
- return docs . Count > 0 ? Doc . Concat ( docs ) : Doc . Null ;
386
+ return Doc . Concat ( ref docs ) ;
387
387
}
388
388
389
389
private static bool IsSingleLineComment ( SyntaxKind kind ) =>
0 commit comments