-
Notifications
You must be signed in to change notification settings - Fork 234
Replace bad StringReader usage with String.Split() #784
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
|
||
return list; | ||
} | ||
return new List<string>(text.Split(s_newlines, StringSplitOptions.None)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So I take it this splits by \r\n
if it finds \r\n
and then splits by \n
if it just finds \n
? Just want to make sure that it doesn't get split by \n
if it finds a \r\n
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh you raise an excellent point! I need to reorder the array:
To avoid ambiguous results when strings in separator have characters in common, the Split operation proceeds from the beginning to the end of the value of the instance, and matches the first element in separator that is equal to a delimiter in the instance. The order in which substrings are encountered in the instance takes precedence over the order of elements in separator.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM 👍 after you get CI to pass
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm... do we really need to store each line every single edit? Always struck me as odd but I never looked into why we were doing it. It'd be great if we could maybe just store the offsets until something actually called GetLines()
.
I don't know how efficient the full framework implementation of string.Split
is but I'm sure the net core is more than good enough. It's probably not worth over engineering this unless we can do away with allocating a string for every line.
Maybe take a peek and see how feasible it would be to change that, otherwise LGTM.
@SeeminglyScience this change should only affect ScriptFile creation right? Like reading in a file for the first time: PowerShellEditorServices/src/PowerShellEditorServices/Workspace/ScriptFile.cs Lines 135 to 156 in 705eff5
The actual lines are managed by that PowerShellEditorServices/src/PowerShellEditorServices/Workspace/ScriptFile.cs Lines 341 to 430 in 705eff5
This list of lines data structure is similar to how I've actually been thinking about exploring other text-editor data structures to possibly optimise the efficiency of storing and editing our version of files. A few that I've heard of and might be worth looking at are: |
@rjmholt Yeah nevermind... I forgot the change event only gives us partials. Definitely not worth messing with in this PR. LGTM! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
Fixes #781.
See also: https://github.com/dotnet/corefx/issues/32990.
StringReader.ReadLine()
likes to ditch the last line in a file if it's a newline.The simplest approach is to replace with a
String.Split()
, which I've done in this PR.This would probably help up with all the off-by-one errors we keep seeing.
If we don't think
String.Split()
is efficient enough (or want to deduplicate the creation of the array and feeding it into a list), I would be very happy to rewrite this manually.