File tree Expand file tree Collapse file tree 1 file changed +19
-11
lines changed
Expand file tree Collapse file tree 1 file changed +19
-11
lines changed Original file line number Diff line number Diff line change 11// ReSharper disable UnusedVariable
22
3+ public delegate bool RemoveLine ( CharSpan line ) ;
4+
35static class Extensions
46{
57 static HashSet < Type > numericTypes =
@@ -152,26 +154,32 @@ public static string NameWithParent(this Type type)
152154 return null ;
153155 }
154156
155- public static void FilterLines ( this StringBuilder input , Func < string , bool > removeLine )
157+ // public static void FilterLines(this StringBuilder input, Func<string, bool> removeLine) =>
158+ // FilterLines(input, (CharSpan line) => removeLine(line.ToString()));
159+
160+ public static void FilterLines ( this StringBuilder input , RemoveLine removeLine )
156161 {
157- var theString = input . ToString ( ) ;
158- using var reader = new StringReader ( theString ) ;
162+ if ( input . Length == 0 )
163+ {
164+ return ;
165+ }
166+
167+ var span = input . AsSpan ( ) ;
168+ var hasTrailingNewline = span [ ^ 1 ] == '\n ' ;
169+
159170 input . Clear ( ) ;
160171
161- while ( reader . ReadLine ( ) is { } line )
172+ foreach ( var line in span . EnumerateLines ( ) )
162173 {
163- if ( removeLine ( line ) )
174+ if ( ! removeLine ( line ) )
164175 {
165- continue ;
176+ input . AppendLineN ( line ) ;
166177 }
167-
168- input . AppendLineN ( line ) ;
169178 }
170179
171- if ( input . Length > 0 &&
172- ! theString . EndsWith ( '\n ' ) )
180+ if ( input . Length > 0 && ! hasTrailingNewline )
173181 {
174- input . Length -= 1 ;
182+ input . Length -- ;
175183 }
176184 }
177185
You can’t perform that action at this time.
0 commit comments