Inspired by a question asked in PR 261728.
Details
Diff Detail
- Repository
- rG FreeBSD src repository
- Lint
Lint Not Applicable - Unit
Tests Not Applicable
Event Timeline
This doesn't follow the Don't Repeat Yourself principle, but currently I don't have a better idea how to express this code.
bin/sh/histedit.c | ||
---|---|---|
671 | verify if the allocation fails? |
bin/sh/histedit.c | ||
---|---|---|
671 | This part is a copy-paste from the while loop above. In each case, if strdup/strndup fails, it returns a null pointer which is assigned to matches[++i]. The next consumer of that is libedit which handles this as nice as I can imagine. We could perhaps break the loop on allocation failure, but it's a potential microoptimization in a corner case, I think. |
This doesn't follow the Don't Repeat Yourself principle, but currently I don't have a better idea how to express this code.
The code doesn't really repeat itself since there was nothing before that returned a list of builtins.
bin/sh/histedit.c | ||
---|---|---|
669 | The MIN seems incorrect. Instead, if curpos > bp[0], it's not a match. |
Reduce code duplication.
I was worried about some repetitive code here when adding the second source of commands (built-ins, after files from $PATH), but it became visibly worse when I started working on adding a third source (aliases). So the sooner I factor this out, the cleaner the future commits will be.