@@ -233,7 +233,7 @@ private static Doc PrivatePrintLeadingTrivia(
233
233
return Doc . Null ;
234
234
}
235
235
236
- var docs = new List < Doc > ( ) ;
236
+ var docs = new ValueListBuilder < Doc > ( [ null , null , null , null , null , null , null , null ] ) ;
237
237
238
238
// we don't print any new lines until we run into a comment or directive
239
239
// the PrintExtraNewLines method takes care of printing the initial new lines for a given node
@@ -246,18 +246,18 @@ private static Doc PrivatePrintLeadingTrivia(
246
246
247
247
if ( printNewLines && kind == SyntaxKind . EndOfLineTrivia )
248
248
{
249
- if ( docs . Count > 0 && docs [ ^ 1 ] == Doc . HardLineSkipBreakIfFirstInGroup )
249
+ if ( docs . Length > 0 && docs [ ^ 1 ] == Doc . HardLineSkipBreakIfFirstInGroup )
250
250
{
251
251
printNewLines = false ;
252
252
}
253
- docs . Add ( Doc . HardLineSkipBreakIfFirstInGroup ) ;
253
+ docs . Append ( Doc . HardLineSkipBreakIfFirstInGroup ) ;
254
254
}
255
255
if ( kind is not ( SyntaxKind . EndOfLineTrivia or SyntaxKind . WhitespaceTrivia ) )
256
256
{
257
257
printNewLines = true ;
258
258
}
259
259
260
- void AddLeadingComment ( CommentType commentType )
260
+ void AddLeadingComment ( CommentType commentType , ref ValueListBuilder < Doc > docs )
261
261
{
262
262
var comment = trivia . ToFullString ( ) . TrimEnd ( '\n ' , '\r ' ) ;
263
263
if (
@@ -269,43 +269,43 @@ void AddLeadingComment(CommentType commentType)
269
269
comment = leadingTrivia [ x - 1 ] + comment ;
270
270
}
271
271
272
- docs . Add ( Doc . LeadingComment ( comment , commentType ) ) ;
272
+ docs . Append ( Doc . LeadingComment ( comment , commentType ) ) ;
273
273
}
274
274
275
275
if ( IsSingleLineComment ( kind ) )
276
276
{
277
- AddLeadingComment ( CommentType . SingleLine ) ;
278
- docs . Add (
277
+ AddLeadingComment ( CommentType . SingleLine , ref docs ) ;
278
+ docs . Append (
279
279
kind == SyntaxKind . SingleLineDocumentationCommentTrivia
280
280
? Doc . HardLineSkipBreakIfFirstInGroup
281
281
: Doc . Null
282
282
) ;
283
283
}
284
284
else if ( IsMultiLineComment ( kind ) )
285
285
{
286
- AddLeadingComment ( CommentType . MultiLine ) ;
286
+ AddLeadingComment ( CommentType . MultiLine , ref docs ) ;
287
287
}
288
288
else if ( kind == SyntaxKind . DisabledTextTrivia )
289
289
{
290
- docs . Add ( Doc . Trim , trivia . ToString ( ) ) ;
290
+ docs . Append ( Doc . Trim , trivia . ToString ( ) ) ;
291
291
}
292
292
else if ( IsRegion ( kind ) )
293
293
{
294
294
var triviaText = trivia . ToString ( ) ;
295
- docs . Add ( Doc . HardLineIfNoPreviousLine ) ;
296
- docs . Add ( Doc . Trim ) ;
297
- docs . Add (
295
+ docs . Append ( Doc . HardLineIfNoPreviousLine ) ;
296
+ docs . Append ( Doc . Trim ) ;
297
+ docs . Append (
298
298
kind == SyntaxKind . RegionDirectiveTrivia
299
299
? Doc . BeginRegion ( triviaText )
300
300
: Doc . EndRegion ( triviaText )
301
301
) ;
302
- docs . Add ( Doc . HardLine ) ;
302
+ docs . Append ( Doc . HardLine ) ;
303
303
}
304
304
else if ( trivia . IsDirective )
305
305
{
306
306
var triviaText = trivia . ToString ( ) ;
307
307
308
- docs . Add (
308
+ docs . Append (
309
309
// adding two of these to ensure we get a new line when a directive follows a trailing comment
310
310
Doc . HardLineIfNoPreviousLineSkipBreakIfFirstInGroup ,
311
311
Doc . HardLineIfNoPreviousLineSkipBreakIfFirstInGroup ,
@@ -323,16 +323,16 @@ void AddLeadingComment(CommentType commentType)
323
323
)
324
324
{
325
325
x ++ ;
326
- docs . Add ( Doc . HardLineSkipBreakIfFirstInGroup ) ;
326
+ docs . Append ( Doc . HardLineSkipBreakIfFirstInGroup ) ;
327
327
}
328
328
printNewLines = false ;
329
329
}
330
330
}
331
331
}
332
332
333
- while ( skipLastHardline && docs . Count != 0 && docs . Last ( ) is HardLine or NullDoc )
333
+ while ( skipLastHardline && docs . Length != 0 && docs [ ^ 1 ] is HardLine or NullDoc )
334
334
{
335
- docs . RemoveAt ( docs . Count - 1 ) ;
335
+ docs . Pop ( ) ;
336
336
}
337
337
338
338
if ( context . State . NextTriviaNeedsLine )
@@ -343,7 +343,7 @@ void AddLeadingComment(CommentType commentType)
343
343
}
344
344
else
345
345
{
346
- var index = docs . Count - 1 ;
346
+ var index = docs . Length - 1 ;
347
347
while (
348
348
index >= 0
349
349
&& ( docs [ index ] is HardLine or LeadingComment || docs [ index ] == Doc . Null )
@@ -354,7 +354,7 @@ void AddLeadingComment(CommentType commentType)
354
354
// this handles an edge case where we get here but already added the line
355
355
// it relates to the fact that single line comments include new line directives
356
356
if (
357
- index + 2 >= docs . Count
357
+ index + 2 >= docs . Length
358
358
|| ! ( docs [ index + 1 ] is HardLine && docs [ index + 2 ] is HardLine )
359
359
)
360
360
{
@@ -364,7 +364,7 @@ void AddLeadingComment(CommentType commentType)
364
364
context . State . NextTriviaNeedsLine = false ;
365
365
}
366
366
367
- return docs . Count > 0 ? Doc . Concat ( docs ) : Doc . Null ;
367
+ return docs . Length > 0 ? Doc . Concat ( ref docs ) : Doc . Null ;
368
368
}
369
369
370
370
private static bool IsSingleLineComment ( SyntaxKind kind ) =>
0 commit comments