Refactoring a "simple" function in dmd source

Walter Bright newshound2 at digitalmars.com
Sun Dec 31 08:25:33 UTC 2023


1. return an InputRange rather than an array of lines
2. no longer do any memory allocation (yay!)
3. no more leaking memory
4. stops processing the source text when the desired line is found
5. support Unicode line endings
6. uses Voldemort return value
7. is pure, @safe, @nogc and all that good stuff
8. much faster
9. completely self-contained

https://github.com/dlang/dmd/pull/15972

and that doesn't even include an earlier refactor:

https://github.com/dlang/dmd/pull/15969

I eyeballed std.string.splitLines() when doing this refactor, and noticed that 
it also allocated memory unnecessarily.

It's more lines of code, but the lines are simpler, and there's not a clever 
thing in it!


More information about the Digitalmars-d mailing list