Skip to content

Commit 0b1f3af

Browse files
committed
Replace bad StringReader usage with String.Split()
1 parent cb713f2 commit 0b1f3af

File tree

1 file changed

+7
-20
lines changed

1 file changed

+7
-20
lines changed

src/PowerShellEditorServices/Workspace/ScriptFile.cs

+7-20
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,12 @@ public class ScriptFile
2020
{
2121
#region Private Fields
2222

23+
private static readonly string[] s_newlines = new []
24+
{
25+
"\n",
26+
"\r\n"
27+
};
28+
2329
private Token[] scriptTokens;
2430
private Version powerShellVersion;
2531

@@ -215,26 +221,7 @@ internal static List<string> GetLinesInternal(string text)
215221
throw new ArgumentNullException(nameof(text));
216222
}
217223

218-
// ReadLine returns null immediately for empty string, so special case it.
219-
if (text.Length == 0)
220-
{
221-
return new List<string> {string.Empty};
222-
}
223-
224-
using (var reader = new StringReader(text))
225-
{
226-
// 50 is a rough guess for typical average line length, this saves some list
227-
// resizes in the common case and does not hurt meaningfully if we're wrong.
228-
var list = new List<string>(text.Length / 50);
229-
string line;
230-
231-
while ((line = reader.ReadLine()) != null)
232-
{
233-
list.Add(line);
234-
}
235-
236-
return list;
237-
}
224+
return new List<string>(text.Split(s_newlines, StringSplitOptions.None));
238225
}
239226

240227
/// <summary>

0 commit comments

Comments
 (0)