Rewrite almost the whole codebase.
Created by: ticki
Many of the tools and code were a mess, so I decided to rewrite almost all of it. The following bullet points sums up what was wrong before:
- Error messages: The error messages from the OS were either 1) ignored, and thus not given as useful information to the end user. 2) "wrapped" in another message. This lead to ugly bugs like messages as
ls: error: couldn't read directory: 'unable to open directory'
. - Exit statuses: Only 3 of the utilities used exit statuses. 2 of the utilities used direct panics (which weren't formatted properly to the end user). This is now fixed, no reachable panics, unwraps of Results are replaced with a println! (which prints
err.description()
from theError
trait) together with anexit(1)
. - Lack of ender: Multiple utilities lacked of EOF, EOL etc.
- Too many allocations: There were a lot unnecessary heap allocations, which were redundant or unnecessary. Most of these are gone now.
- Changes in
wc
: I added man page forwc
, rewrote parts of the code to yield a better performance, made arguments composable, and completed a few TODOs. cc @alicemaz - Warnings: Warnings, warnings everywhere.
- Nested indentation: Helper functions are your friend!
- Lack of abstractions: Many of the utilities lacked of abstraction, and were pretty hacky. I have added an 'extra' module in the
coreutils
library, which contains all sorts of helper functions which are frequently used. - Too many formatters: Formatters can be slow, especially when the concatenation can be done via sequential writes. No reason for putting in an extra allocation there.
- Missing reuse of stdin: It isn't that obvious that
print!
and friends actually constructs a newStdin
each time they're called, so not only do they use a formatter, but they do also, potentially, make an unnecessarily construction of a Stdin, which on certain platforms is expensive. -
to_string()
is evil too: ToString is not specialized, and will always use a formatter, and you know, formatters are evil.
I hope you're fine with this.